Print Page | Close Window

DateTime issue

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3504
Printed Date: 13-May-2026 at 4:54am


Topic: DateTime issue
Posted By: Vonzkie
Subject: DateTime issue
Date Posted: 21-Jun-2012 at 3:47am
Hi,

We have a problem in our application that if our client end has a timezone different to the server's timezone the date is converted to the database.

How can we eliminate that by applying fixes to all datetime values without applying it to each field of each entity?

BTW, we're using Database First approach.

Thanks,
Von



Replies:
Posted By: mgood
Date Posted: 21-Jun-2012 at 11:01am
If your application deals with multiple timezones you should store dates and times relative to Coordinated Universal Time (UTC) and then convert them to local time and back on the client. The easiest way to do that is by using DateTimeOffset instead of DateTime. DateTimeOffset represents a point in time relative to UTC and has all the conversion logic built-in to get the local time through the LocalDateTime property. 

If you can't change your data model to use DateTimeOffset, then you should do the conversion yourself and always store data time in UTC. The following post has some useful information regarding this topic.

http://stackoverflow.com/questions/246498/creating-a-datetime-in-a-specific-time-zone-in-c-sharp-fx-3-5 - http://stackoverflow.com/questions/246498/creating-a-datetime-in-a-specific-time-zone-in-c-sharp-fx-3-5


Posted By: Vonzkie
Date Posted: 28-Jun-2012 at 2:22am
Hi,

Thanks for the info..
However, I'm having hard time understanding this.. 
Our requirement is just simple, regardless of the timezone between client and server, we want to save and retrieve the date value in the way we entered it.

Thanks,
Von


Posted By: mgood
Date Posted: 28-Jun-2012 at 1:36pm
Sorry, I missunderstood you. Both DevForce and Entity Framework use DateTimeKind.Unspecified for any DateTime property, so nothing should mess with it, because there isn't enough information to do any conversion. Are you setting the DateTimeKind yourself to something other than Unspecified?



Print Page | Close Window