New Posts New Posts RSS Feed: DateTime issue
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

DateTime issue

 Post Reply Post Reply
Author
Vonzkie View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01-Aug-2011
Location: PH
Posts: 133
Post Options Post Options   Quote Vonzkie Quote  Post ReplyReply Direct Link To This Post Topic: DateTime issue
    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
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
Vonzkie View Drop Down
Senior Member
Senior Member
Avatar

Joined: 01-Aug-2011
Location: PH
Posts: 133
Post Options Post Options   Quote Vonzkie Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down