Should all queries on date be utc?

58 views
Skip to first unread message

ZNS

unread,
Aug 22, 2013, 11:45:46 AM8/22/13
to rav...@googlegroups.com

I have documents which represents events. These events happen at a certain moment in time and I use a DateTimeOffset property to store the date with timezone information to ravendb. To this I have a service stack rest api set up. Through the api you can query for all events that take place between two dates. So you can pass for example "20013-08-22" as a querystring which service stack will parse into a DateTime object. I query my events through an index using LuceneQuery like this WhereBetweenOrEqual("Date", request.DateFrom, request.DateTo); Should I convert dates to UTC before passing them here?

Mircea Chirea

unread,
Aug 22, 2013, 11:52:14 AM8/22/13
to rav...@googlegroups.com
Ahh, the lovely topic of date and time. I have two words of advice for you:
  1. Read this article: http://ravendb.net/kb/61/working-with-date-and-time-in-ravendb
  2. Only listen to Matt Johnson and whoever Matt agrees with (for this topic).

Kijana Woodard

unread,
Aug 22, 2013, 12:24:26 PM8/22/13
to rav...@googlegroups.com

+1 :-)

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Matt Johnson

unread,
Aug 22, 2013, 1:21:39 PM8/22/13
to rav...@googlegroups.com
The setup sounds just fine.

In your query, the parameters can be either DateTime with Utc kind, or DateTimeOffset.  You'll only have trouble if you try to pass DateTime with Local or Unspecified kind (for this scenario).

The question to consider is "who's day are you talking about"?  If it's the user's day, then make sure you know the time zone of the user.

ZNS

unread,
Aug 23, 2013, 4:10:23 AM8/23/13
to rav...@googlegroups.com

Good advice and that is one great article. Thanks!
Reply all
Reply to author
Forward
0 new messages