Tutorial :How do I set a global DateTime format in an ASP.NET project?



Question:

I have a server with German windows on it, but the DateTime values are stored on a mysql server in English format. How do i force every DateTime.ToString() method (like DateTime.Now.ToString()) to output an 'English' DateTime by default?


Solution:1

I'd set the culture in the web.config so any culture specific conversion or parsing i.e. dates, will use the same culture regardless of the underlying operating system region.

i.e.

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


Solution:2

I would suggest you try and make your mysql environment and you .net environment to both use a Universal datetime format rather than a localised version. Then you can use DateTime.ToString("U") to use a reliable format at all times.

Aside from that though, you should be able to pass your dates to your database as date typed parameters rather than as a string and therefore it will handle the underlying conversion for you. I use SqlServer though not MySql so I don't know if you get the same results.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »