Thursday, 12 July 2012

Date Parsing issues in C# (Regional Settings in Windows 2008)


A while ago I posted about some issues we had while parsing dates in a .NET application, well it was a MS Dynamics CRM application, but the code itself was a simple, run of the mill, web method.

Imagine my surprise when yesterday I had to sort out a similar issue for a new project I'm working on, though this time there were a couple of differences:
  1. No domain account was being used for the application pools.
  2. Operating System was Windows 2008 R2 Enterprise edition.
  3. Everybody concerned was convinced that it had been working up until now.
In all likelihood, it had only worked, because they had not looked far enough in to the future, i.e. they were parsing 10/07/2012, (i.e. 10th July) which would be parsed as 7th October, so when they tried 13/07/2012 the system stopped working.

The source of the problem as well as the solution were the same as last time:
  • The source: Using US version of Windows.
  • The solution: Set all users to UK settings.
This is accomplished like this (I assume that you have set up your current user with the local settings that you want, in my case UK):
  1. Open Region and Language section of Control Panel (Start | Control Panel | Region and Language)


  2. Select Administrative tab.


  3. Click Copy Settings.


  4. Tick as per screenshot.


  5. Click OK twice.
This sets all user and system accounts to use the same regional settings and solved all of our date parsing problems.

3 comments: