Windows has language packages that store country specific settings such as short date format. I have recently came across an issue that was caused by an update in Canada’s language package.
Starting with Windows Server 2012 and Windows 8, the default date format for English (Canada) – short name is
en-CA – was changed from
Microsoft is not planning to revert this change as
yyyy-MM-dd is the recommended date format by The Government of Canada. However, there is no binding legislation so other formats are also used.
The Government of Canada recommends that all-numeric dates in both English and French use the YYYY–MM–DD format codified in ISO 8601. The Standards Council of Canada also specifies this as the country’s date format.
The YYYY–MM–DD format is the only method of writing a numeric date in Canada that allows unambiguous interpretation, and the only officially recommended format. The presence of the DD/MM/YY (international) and MM/DD/YY (American) formats often results in misinterpretation. Using these systems, the date 7 January 2016 could be written as either 07/01/16 or 01/07/16, which readers can also interpret as 1 July 2016 (or 1916); conversely, 2016-01-07 cannot be interpreted as another date.
In spite of its official status and broad usage, there is no binding legislation requiring the use of the YYYY–MM–DD format, and other date formats continue to appear in many contexts.Date and time notation in Canada
Workaround for the short date format in Canada
A quick fix would be changing the date string before using it in the application. For example:
string displayOnPage2 = Calendar1.SelectedDate.ToString("dd/MM/yy");
If you are using
CultureInfo class, you can also change the short date pattern:
CultureInfo ci = CultureInfo.CreateSpecificCulture("en-CA"); DateTimeFormatInfo dtfi = ci.DateTimeFormat; dtfi.ShortDatePattern ="dd/MM/yyyy"; string displayOnPage1= Calendar1.SelectedDate.ToString("d", dtfi);
If you are seeing “date format not recognized” error after the changes, please have a look at this post: Solved: “ORA-01830: date format picture ends before converting entire input string” and “ORA-01821: date format not recognized”
If you are fine with changing the server’s Region settings, this might be the solution you are looking for. It changes the format back to
dd/MM/yyyy (or whichever date format you want) as long as you keep your server in that region. If you switch the region to another one, Windows reverts the changes back to the default so the application starts using
As many developers and system administrators don’t want to change their machines’ settings, my recommendation would be making a code change instead as explained in the Workaround section above.