views:

339

answers:

3

I recently switched my hosting provider and due to the time zone that the server is now in, my code has stopped working.

The hosting server reports in Pacific time, However, my code needs to work with GMT as my site is for the UK market. So, all my displays and searches need to be in the format dd/MM/yyyy

How can I account for the difference?

For instance, when I do a DateTime.Parse("03/11/2008") it fail as I assume the 'Parse' is against the servers settings. I also get "String was not recognized as a valid DateTime." throughout my code.

+3  A: 

Try

DateTime.Parse("28/11/2008", new CultureInfo("en-GB"))

Have a look at the overload for DateTime.Parse on MSDN.

Also, be careful not to confuse time zones (pacific, GMT) with cultures. Cultures are your actual problem here.

Ray
+4  A: 

In your web.config file add <globalization> element under <system.web> node:

<system.web>
  <globalization culture="en-gb"/>
  <!-- ... -->
</system.web>
Pavel Chuchuva
Thank you, thank you, thank you... It worked beautifully.
Skittles
+1  A: 

In order to avoid dealing with these very boring issues, I advise you to allways parse your data following the standard and unique SQL/ISO date format which is YYYY-MM-DD. Your queries will then work internationally, whatever are the date parameters on your main server or on the querying clients (where local date settings might be different than main server settings)!

Philippe Grondier