none
Parse Date differences between W7 and Server2012 R2 RRS feed

  • Question

  • DateTime Date;

    DateTime.TryParse("01.09.2015", (new CultureInfo("en-CA")), DateTimeStyles.None, out Date);

    gives different results:

    Watch Date:

     

    Windows 7 SP1

     

    Date   {01.09.2015 00:00:00}      System.DateTime

    Date   {01.09.2015 00:00:00}      System.DateTime

    Day    1      int

    DayOfWeek    Tuesday      System.DayOfWeek

    DayOfYear    244    int

    Hour   0      int

    Kind   Unspecified  System.DateTimeKind

    Millisecond  0      int

    Minute 0      int

    Month  9      int

    Second 0      int

    Ticks  635766624000000000  long

    TimeOfDay    {00:00:00}   System.TimeSpan

    Year   2015   int

                

     

    Windows Server 2012 R2 Standard

     

    Date   {1/9/2015 12:00:00 AM}     System.DateTime

    Date   {1/9/2015 12:00:00 AM}     System.DateTime

    Day    9      int

    DayOfWeek    Friday System.DayOfWeek

    DayOfYear    9      int

    Hour   0      int

    Kind   Unspecified  System.DateTimeKind

    Millisecond  0      int

    Minute 0      int

    Month  1      int

    Second 0      int

    Ticks  635563584000000000  long

    TimeOfDay    {00:00:00}   System.TimeSpan

    Year   2015   int

          
    Is there an explanation for this behaviour ? An error or an feature ? Any patches needed ?

    Tuesday, October 13, 2015 6:45 AM

Answers

  • Hi RolfSt,

    You could use below code to see the right date format of en-CA.

    var ca = new CultureInfo("en-CA");
    Console.WriteLine("{0}: {1}", ca.Name, ca.DateTimeFormat.ShortDatePattern);

    The output on my side is "yyyy-MM-dd". Your given string is not in the right format. I suggest you use TryParseExact method.

    DateTime Date;
    DateTime.TryParseExact("01.09.2015", "dd.MM.yyyy", (new CultureInfo("en-CA")), DateTimeStyles.None, out Date);

    Best Regards,
    Li Wang

    Wednesday, October 14, 2015 1:29 AM
    Moderator

All replies

  • DateTime Date;

    DateTime.TryParse("01.09.2015", (new CultureInfo("en-CA")), DateTimeStyles.None, out Date);

    gives different results:

    Watch Date:

     

    Windows 7 SP1

     

    Date   {01.09.2015 00:00:00}      System.DateTime

    Date   {01.09.2015 00:00:00}      System.DateTime

    Day    1      int

    DayOfWeek    Tuesday      System.DayOfWeek

    DayOfYear    244    int

    Hour   0      int

    Kind   Unspecified  System.DateTimeKind

    Millisecond  0      int

    Minute 0      int

    Month  9      int

    Second 0      int

    Ticks  635766624000000000  long

    TimeOfDay    {00:00:00}   System.TimeSpan

    Year   2015   int

                

     

    Windows Server 2012 R2 Standard

     

    Date   {1/9/2015 12:00:00 AM}     System.DateTime

    Date   {1/9/2015 12:00:00 AM}     System.DateTime

    Day    9      int

    DayOfWeek    Friday System.DayOfWeek

    DayOfYear    9      int

    Hour   0      int

    Kind   Unspecified  System.DateTimeKind

    Millisecond  0      int

    Minute 0      int

    Month  1      int

    Second 0      int

    Ticks  635563584000000000  long

    TimeOfDay    {00:00:00}   System.TimeSpan

    Year   2015   int

          
    Is there an explanation for this behaviour ? An error or an feature ? Any patches needed ?


    Tuesday, October 13, 2015 11:58 AM
  • Hi RolfSt,

    You could use below code to see the right date format of en-CA.

    var ca = new CultureInfo("en-CA");
    Console.WriteLine("{0}: {1}", ca.Name, ca.DateTimeFormat.ShortDatePattern);

    The output on my side is "yyyy-MM-dd". Your given string is not in the right format. I suggest you use TryParseExact method.

    DateTime Date;
    DateTime.TryParseExact("01.09.2015", "dd.MM.yyyy", (new CultureInfo("en-CA")), DateTimeStyles.None, out Date);

    Best Regards,
    Li Wang

    Wednesday, October 14, 2015 1:29 AM
    Moderator