views:

59

answers:

3

I have a site that saves a date in my model to the database.

After launching my site I realised that the server has US regional settings so I had to make sure that all date's on the public site were formatted in the UK format.

However now when I go to my 'Create' page and choose a date and click save I get the error The value '22/11/2009' is not valid for the Date field. which must be coming from the default DataAnnotations on my model.

Is there something I can do to get it to accept UK formatted dates?

+1  A: 

Have you tried this? If this site is only used in the UK, you can probably put this in the Global.asax Application_Init. If it is based on the user, you can put it in Application_BeginRequest. This will provide the default formatting and parsing for all dates and numbers in the application.

Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-gb");
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-gb");
Brian
+1  A: 

Do what SO does: persist all dates in UTC and render them as UCT with an appended "Z" for GMT/UTC/Zulu. It might not be ideal but sometimes the gain from simplicity outweighs the costs of the alternative. Think about that.

cottsak
+2  A: 

I managed to get it working by putting this into the web.config

<globalization culture="en-GB"/>
Jon