If one only works with dates and no time, would it still be wise to save all your dates in UTC for a multi timezone app?
Asked
Active
Viewed 1,734 times
2 Answers
3
I suggest using DateTimeOffset
- this allows you to store both the DateTime
and the UTC offset.
Also, read this SO question about timezone best practices.
-
Would you then save the client's UTC offset? – adriaanp Jun 11 '11 at 19:37
-
@adriaanp - For a timezone sensitive application, yes. – Oded Jun 11 '11 at 19:38
-
I am getting confused with this. Lets say the client entered 6/11/2011 then I save 6/11/2011 12:00:00 AM -07:00 (client's timezone) If the server's UTC offset is +02:00 and I want to query dates should I use DateTimeOffset.Now or DateTimeOffset.Now.Date? – adriaanp Jun 11 '11 at 20:01
-
@adriaanp - `DateTimeOffset.Now` will return the current Time as well as the Date, `DateTimeOffset.Now.Date` will not. – Oded Jun 11 '11 at 20:06
-
1sorry I am not being clear. What I meant was, what should I use on the server side to query the dates? – adriaanp Jun 11 '11 at 20:30
3
The general the answer is yes, but it will introduce errors in time conversion if time part is not stored. Timezone conversions need time part to produce meaningful results. So just store full UTC time (i.e. date and time), since you can always trim it to just date if necessary.

Petr Abdulin
- 33,883
- 9
- 62
- 96