That's why storing DateTimes as string in database is a bad practice and should be avoided at all costs.
The best to do is :
- to store values as DateTime in the database, preferably in UTC ;
- to display values on clients according to local time/regional format. Below are some useful links about methods you can use for that.
DateTime.ToLocalTime Method[
^]
DateTime.ToUniversalTime Method[
^]
DateTime.ToString Method (IFormatProvider)[
^]
Coordinated Universal Time[
^]
Examples :
Storing a DateTime value in database from client:
DateTime date = dateTimePicker.Value.ToUniversalTime();
cmd.CommandText = "UPDATE Invoices SET InvoiceDate = @myDate WHERE InvoiceId = @currentId";
cmd.Parameters.AddWithValue("@myDate", date);
cmd.Parameters.AddWithValue("@currentId", currentId);
cmd.ExecuteNonQuery();
Retrieving and displaying a DateTime value on client application:
cmd.CommandText = "SELECT InvoiceId, InvoiceDate FROM Invoices";
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read()) {
DateTime currentDate = ((DateTime)dr["InvoiceDate"]).ToLocalTime();
invoiceDateTextBox.Text = currentDate.ToString(CultureInfo.CurrentUICulture);
}
This way you won't have to bother anymore about DateTime storage and display formats.
These are just some skeletons and give a basic idea about DateTime handling; I hope you get the big picture and are able to adapt it to your current code.