What happens if I set CurrentCultureInfo to en-us

I am using a client application that connects to a remote US database. there are some datetime ambiguities that appear as a result, as if the date was January 14th in the database, it returned as January 13th.

What I would like to know If I set my Client's CurrentCultureInfo equal to my servers, this will fix the problem.

If it can be done ... I would like a small example of the same.

+1


source to share


3 answers


Your culture is used for formatting. The problem that you think has one of the different time zones.



My simple solution is to always store dates and times in UTC. You can use DateTime.UtcNow to do this with a client, and you can convert it back to local time later if needed.

+1


source


The problem is that the US has several different time zones, so this cannot be a solution. One workaround I can think of would be to set the client machine's timezone to the server, but something about that just doesn't sound right.



0


source


If you can't change the storage date in UTC and convert back and forth when inserting and selecting data. Then, if your data is not inserted into the server, you will have to write something that tells you where the data came from (I mean the local timezone of the client that inserted the data).

If your data is just being inserted into the server, then you can probably use the SQL functions GetUTCDate and compare it to GetDate and then subtract the result from your datetime stored in the database. Then, on the client, use DateTime.ToLocalTime () to convert the return value to local time. As I said, this will only work if the data is exclusively inserted into the server, or at least by clients in the same timezone. Otherwise, forget about it.

0


source







All Articles