DateTimeFormatInfo.MonthDayPattern Has Changed in Windows Server 2012 - How Can I set it back?
Asked Answered
C

1

6

In Australia, A client has been entering "1/5" as a shortcut for the first day of May. We have just moved from Windows Server 2008 to Windows Server 2012.

Using the following code in LinqPad:

Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-au", false);
System.Globalization.DateTimeFormatInfo.CurrentInfo.MonthDayPattern.Dump();
DateTime.Parse("1/5").Dump();

On Windows Server 2008:

dd MMMM

1/05/2016 12:00:00 AM

On Windows Server 2012 R2:

MMMM d

5/01/2016 12:00:00 AM

Questions:

  1. Why has the MonthDayPattern changed? Australians always have day first, then month
  2. Where can this be set in the Windows Server UI? The UI only exposes the long and short formats, not the month and day format
  3. How can I fix the issue in my application with the least amount of changes, given that there could be DateTime.Parse happening all through the system (Eg. Model Binding, Validation etc)
Cerulean answered 7/7, 2016 at 0:20 Comment(2)
Which version of Linqpad are you using?Upwards
4, we don't have .Net 4.6 on the server so can't use 5Cerulean
U
2

I can replicate the issue on Windows Server 2012. If you add...

System.Globalization.DateTimeFormatInfo.CurrentInfo.ShortDatePattern.Dump();  

you'll see it returns...

d/MM/yyyy

It's only the MonthDayPattern which seems to be incorrect. This might be a bug. I would log the issue on https://connect.microsoft.com/.

In the mean time you could simply set the MonthDayPattern....

Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-au", false);
System.Globalization.DateTimeFormatInfo.CurrentInfo.ShortDatePattern.Dump();
System.Globalization.DateTimeFormatInfo.CurrentInfo.MonthDayPattern.Dump();
DateTime.Parse("1/5").Dump();
System.Globalization.DateTimeFormatInfo.CurrentInfo.MonthDayPattern = "d MMMM";
DateTime.Parse("1/5").Dump();

On Windows Server 2012 R2:

d/MM/yyyy

MMMM d

5/01/2016 12:00:00 AM

1/05/2016 12:00:00 AM

Upwards answered 7/7, 2016 at 4:14 Comment(2)
I think you are correct, the easiest solution will be to set the format ourselves on the thread. Still doesn't explain why the problem exists, so i'll raise an issue on connect....Cerulean
Hey @Cerulean - did you ever hear anything from Microsoft about this? I've just hit a very similar issue. My server switches from dd MMMM to d MMMM which made the bug even more random and confusing...Systematics

© 2022 - 2024 — McMap. All rights reserved.