views:

129

answers:

3

I am using a client application which connects to a remote Database in US. there are some datetime ambiguities that comes up in the result like if date is 14 Jan in database its returned as 13 Jan.

What I would like to know If I Set the CurrentCultureInfo of my Client equal to my Servers will that solve the issue.

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

A: 

The problem is the US itself has a few different time zones, so this couldn't be a solution. One workaround I can think of would be to set the time zone of the client computer to that of the server, but something about that just doesn't sound right.

lc
Well I already thought if that Solution, that's not acceptable
Figured as much. :-)
lc
+1  A: 

Your culture is used for formatting. The issue you seem to have is one of different time zones.

My simple solution to this is to always store dates and times in UTC. You can use DateTime.UtcNow for that from the client, and you can convert it back to local time later if necessary.

Bernhard Hofmann
Yes Buddy I know it. But I am the new guy in this company and they have already coded this piece way back in 2005 and I just cant go and change the Insert Statements.
A: 

If you can't change the date your storing to a UTC time and convert back and forth when inserting and selecting data. Then unless your data is being inserted at the server you're going to have to record something that tells you where the data came from (i mean what the local time zone is of the client that inserted the data).

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

Michael Prewecki
The Thing is I want the date as "it is" no chnage required why this problem is there at all.Fetching a date and displaying it, sounds so simple but creating Hell for me as of now