Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DateTime timezone behavior
Message
From
06/11/2008 10:00:35
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01360004
Message ID:
01360170
Views:
10
>>I have a strange thing happening to my DateTime field in every record being saved to SQL Server. My SQL Server is in Texas (central time zone) but my application is running in pacific time. The computer has the correct pacific time zone time set on it. Every record in the SQL Server database has this time set two hours ahead.
>>
>>I am getting my time from DateTime.Now and then setting a property in an Entity that gets saved to the table.
>>>pre>
>>.. bunch of code
>>//Reset the lastLogTime
>>this.lastLogTime = DateTime.Now;
>>.. some code that doesn't touch the lastLogTime
>>// Build the SpotStarter object
>>SpotStarterEntity oSpotStarter = new SpotStarterEntity();
>>
>>oSpotStarter.Track_id = Guid.NewGuid();
>>oSpotStarter.Record_Status = type;
>>oSpotStarter.Spot_Latitude = lat;
>>oSpotStarter.Spot_Longitude = lon;
>>oSpotStarter.Spot_Time = lastLogTime;
>>... Set more properties in the Entity
>>// Save this Entity
>>
>>
>>Since I am also in CT I don't know if I can conclusively test this, but I suppose I could change my computer timezone to something else and try that. Anybody have any ideas why this would happen.
>>Tim
>>
>>Updated: Ok, I forgot to mention that I am using Mere Mortals framework which I will work through and also WCF to get the data up to the server. Might be something in those things, as DateTime.Now sure should just get local computer time.
>
>I think you should always save data in UTC format on the server and display them in local format.

I may have to resort to this. I did find this interesting in the xml file for this date
<Spot_Time>2008-11-01T12:26:11.9375-07:00<Spot_Time>
I suspect that -07 in there has to do with the offset from UTC as the Pacific time zone in the summer (before we just changed) was -7 hours. Funny thing is if this is the case, it didn't get respected when saved. Central time would have been -5 hours.
Tim
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform