none
Date time Format issue in Windows 7 RRS feed

  • Question

  • I have a scenario where in we are fetching datetime from SQL Database in Windows 7 OS.
    If we dont modify the Date Format in Calendar settings and work it says string not recognised as a valid date time, but if we modify the Settings to something else and then work , it has no prob.
    Again if we revert back to the Old Format, it has no problem.?
    Is this a problem of the OS or can it be handled in the Code.

    Tuesday, May 29, 2012 5:04 AM

Answers

  • Hi Chethan,

    I would also suggest you try to set the culture when your application start:

                Application.CurrentCulture = new CultureInfo("en-US");

    Put this code in the Program.cs.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, May 30, 2012 6:05 AM
    Moderator

All replies

  • Hi Chethan Jain,

    these formats are converted according to the culture you are using, if you not mention any culture to your application it will take system culture by default. So set the culture you want in web.config or where ever you need.

    Let me show you some example here please change it accordingly as per your requirement.

    CultureInfo culture = new CultureInfo(“en-US”);
    string today = DateTime.Now.ToString(“d”,culture);

    through out your application your date format will be same.

    Hope it will help you..


    Sai Kumar K (MCP)
    Blog: Sai's Stuff.
    WebSite: SantoshTechnologies.

    Tuesday, May 29, 2012 5:40 AM
  • It is by default set as "en-US".
    Even then the same problem exists.
    Tuesday, May 29, 2012 10:52 AM
  • Hi Chethan,

    I would also suggest you try to set the culture when your application start:

                Application.CurrentCulture = new CultureInfo("en-US");

    Put this code in the Program.cs.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, May 30, 2012 6:05 AM
    Moderator