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?
A:
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.
Robin Day
2009-03-24 10:14:40
Unfortunately, even with type parameters you can definitely still pass badly formatted dates to SQL Server. ASP.NET does not know the date format that your SQL credentials are expecting, which can be set on a per-user basis.
Bryan
2009-03-24 10:25:38
I find it best to always pass a fixed format to SQL Server for dates that cannot be mixed up due to localization issues. MMM dd yyyy handles this as there is no means for it to swap months, days, and years.
schooner
2009-03-24 10:52:27
+3
A:
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"/>
Dan Kennedy
2009-03-24 10:23:04