Saturday, June 4, 2022

DateTime format issues in ASP.NET

There was a prolonged ongoing problem resolution effort in our workplace. It was a mysterious problem that had us all stumped. The problem was DateTime parsing. Strings containing dates were not being parsed "properly" on the server. The same strings were being parsed perfectly when the server program ran on our local computers.

We first checked the date format on the server. The format was changed to match our local machines - "dd/MMM/yyyy". The country/region was set to "India" and the regional format was set to "English (India)". In spite of these changes, the web app behaved differently on the server machine when compared to how it behaved on our machines (laptops and desktops). Then we took a look at the "Current System Locale" setting - buried under Settings -> Region -> Additional date, time & regional settings -> Change date, time or number formats -> Administrative -> Change system locale. However, this was set to English(United States) on both our machines and the server. This meant that this setting was not the cause of the different behavior. The fact that the server OS was Windows 2016 Server edition might be making the difference. But, how do we fix the date-time issue?

Finally, after some googling, I found the following stackoverflow article. Inserting the following XML snippet in the <configuration><system.web> fixed the issue: 

 <globalization uiCulture="en-IN" culture="en-IN" />

No comments:

Post a Comment