akosch
akosch

Reputation: 4396

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

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?

Upvotes: 0

Views: 5176

Answers (2)

Dan Kennedy
Dan Kennedy

Reputation: 810

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"/>

Upvotes: 5

Robin Day
Robin Day

Reputation: 102468

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.

Upvotes: 0

Related Questions