Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DateTime timezone behavior
Message
From
05/11/2008 18:31:37
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
DateTime timezone behavior
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01360004
Message ID:
01360004
Views:
64
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.
Timothy Bryan
Next
Reply
Map
View

Click here to load this message in the networking platform