Linq to SQL DateTime values are local (Kind=Unspecified) - How do I make it UTC?
Posted
by ericsson007
on Stack Overflow
See other posts from Stack Overflow
or by ericsson007
Published on 2009-05-05T04:16:28Z
Indexed on
2010/03/26
13:53 UTC
Read the original article
Hit count: 118
Isn't there a (simple) way to tell Linq To SQL classes that a particular DateTime property should be considered as UTC (i.e. having the Kind property of the DateTime type to be Utc by default), or is there a 'clean' workaround?
The time zone on my app-server is not the same as the SQL 2005 Server (cannot change any), and none is UTC. When I persist a property of type DateTime to the dB I use the UTC value (so the value in the db column is UTC), but when I read the values back (using Linq To SQL) I get the .Kind property of the DateTime value to be 'Unspecified'.
The problem is that when I 'convert' it to UTC it is 4 hours off. This also means that when it is serialized it it ends up on the client side with a 4 hour wrong offset (since it is serialized using the UTC).
© Stack Overflow or respective owner