I'm configuring a new server and have been experiencing issues with parsing dates where the following code worked perfectly on the old server but not the new server.
IFormatProvider fpCanada = System.Globalization.CultureInfo.CreateSpecificCulture("en-CA");
Convert.ToDateTime(strStartDate, this.fpCanada); //en-CA
Error: System.FormatException: String was not recognized as a valid DateTime.
I don't want to have to modify the code to use TryParseExact
or the registry, so my conclusion was to modify the PC's regional settings to match that of the old server.
Old server
Current format: English (Canada)
Short date: dd/MM/yyyy
New server
Current format: English (Canada)
Short date: yyyy-MM-DD
After updating the date format of the PC's regional settings to dd/MM/yyyy, I tried resetting the app pool, but that doesn't seem to have done anything.
// Still returns yyyy-MM-dd
System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern
Am I wrong in assuming that the PC's regional settings have a direct correlation to the ShortDatePattern
in .Net?
PC Regional and Language Settings are being ignored in .Net