Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C# DateTime question...

  • 28-03-2009 7:02pm
    #1
    Closed Accounts Posts: 7,097 ✭✭✭


    I have a line of code that takes date time/timestamp from a form in the format "20090328185714", or YYYYDDMMhhmmss...

    TIMESTAMP.Text = Request.Form["TIMESTAMP"];

    At the moment, I'm putting this on my aspx page using a label:

    <asp:Label ID="TIMESTAMP2" runat="server" Width="685px" ForeColor="#ff3300" Font-Names="verdana" Font-Size="X-Small"></asp:Label>

    What I'd like to do is convert this from an unreadable "20090328185714" type word into something easier on the eye, like 27 March 2009 18:57PM or something more readable. Unfortunately the format of the date coming into my form from a remote server cannot be changed. It looks easy but everytime I try to do it, I keep getting back errors!


Comments

  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Darragh29 wrote: »
    I have a line of code that takes date time/timestamp from a form in the format "20090328185714", or YYYYDDMMhhmmss...

    TIMESTAMP.Text = Request.Form["TIMESTAMP"];

    At the moment, I'm putting this on my aspx page using a label:

    <asp:Label ID="TIMESTAMP2" runat="server" Width="685px" ForeColor="#ff3300" Font-Names="verdana" Font-Size="X-Small"></asp:Label>

    What I'd like to do is convert this from an unreadable "20090328185714" type word into something easier on the eye, like 27 March 2009 18:57PM or something more readable. Unfortunately the format of the date coming into my form from a remote server cannot be changed. It looks easy but everytime I try to do it, I keep getting back errors!

    Do you need the request timestamp, could you create your own one instead such as DateTime myDate = DateTime.Now.ToLongDateString(new CultureInfo.GetCurrentUICulture);

    You can possibly use a DateTime.TryParse(string) and see if it can return it back using a specific culture instance


    For example

    DateTime myDate;

    if(DateTime.TryParse(datestring, out myDate))
    {
    myDate.ToLongDateString(new CultureInfo.GetSpecificCulture("en-ie"));
    }


  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Thanks a mil Ginger. I posted in desparation last night when I was pulling my hair out with this!

    I finally got it sorted using the code below...

    TIMESTAMP.Text = Request.Form["TIMESTAMP"];
    string DTString = TIMESTAMP.Text;
    string DTFormat = "yyyyMMddHHmmss";
    DateTime time1 = DateTime.ParseExact(DTString, DTFormat, CultureInfo.InvariantCulture);
    TIMESTAMP.Text = string.Format("{0:r}", time1);


    I'm glad I stuck with asp.net and c# now, but every now and again, I run into a headwrecker issue!


  • Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭John_Mc


    Darragh29 wrote: »
    Thanks a mil Ginger. I posted in desparation last night when I was pulling my hair out with this!

    I finally got it sorted using the code below...

    TIMESTAMP.Text = Request.Form["TIMESTAMP"];
    string DTString = TIMESTAMP.Text;
    string DTFormat = "yyyyMMddHHmmss";
    DateTime time1 = DateTime.ParseExact(DTString, DTFormat, CultureInfo.InvariantCulture);
    TIMESTAMP.Text = string.Format("{0:r}", time1);


    I'm glad I stuck with asp.net and c# now, but every now and again, I run into a headwrecker issue!

    Glad to hear that you've come around to the .net way of things! :)


Advertisement