Daniel Minnaar
Daniel Minnaar

Reputation: 6295

What's the easiest way to change your date format on a .NET WinForms application using SQL?

We've developed a large winforms application in .NET, and the client has requested to see the information in a different date format.

The problem we've encountered is that if we set the local regional settings to the client's date format, SQL-code bombs out everywhere since the dates being passed to SQL aren't in the same format anymore as SQL expects them.

Is there a way to get around this issue, without having to change my code everywhere, like this? MySqlProvider.SaveLoginDate(theDate.ToString("dd/MM/yyyy");

Upvotes: 1

Views: 146

Answers (1)

Guffa
Guffa

Reputation: 700620

Preferably you should handle date formatting and date parsing in the user interface part of the code, so that you handle DateTime values when you communicate with the database. Specify a culture or a format string when you format and parse dates.

Also, storing the dates as UTC is a good idea if you have users in different time zones. Use the ToLocalTime and ToUniversalTime to convert between UTC and the local time zone.

Upvotes: 2

Related Questions