DateTime format on a hosting server

I recently switched my hosting provider, and due to the time zone in which the server is located, my code stops working.

The hosting server reports in Pacific Time. However, my code should work with GMT, as my site is intended for the UK market. So, all my displays and search queries should be in dd / MM / yyyy format

How can I explain the difference?

For example, when I do DateTime.Parse ("03/11/2008"), it fails because I assume that "Parse" matches the server settings. I also get: "String was not recognized as a valid DateTime." in all my code.

+4
source share
4 answers

In the web.config file, add the <globalization> element to the <system.web> node:

 <system.web> <globalization culture="en-gb"/> <!-- ... --> </system.web> 
+6
source

Try

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

See the overload for DateTime.Parse on MSDN .

Also, be careful not to confuse time zones (peaceful, GMT) with cultures. Cultures are your real problem.

+3
source

In order not to cope with these very boring problems, I advise you to always analyze your data in accordance with the standard and unique SQL / ISO date format, which is YYYY-MM-DD. Then your requests will work internationally, regardless of the date settings on your main server or on request clients (where local date parameters may differ from the settings of the main server)!

+1
source

I had this problem which was not solved above. So maybe this can help someone not tear all their hair apart.

I got NaN-NaN-Nan on the new server in my date text box. It turned out that on the new server there was an Internet explorer option "Show intranet sites in compatibility mode." The workaround here was to

 <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE" / > 

in the aspx header to disable compatibility mode.

This solved a lot of strange things that were happening. Hope this helps someone!

0
source

All Articles