简体   繁体   中英

appengine - query datastore filtering objects by local time

I have a lot of data in the data store and I need to filter it by a date field using some day as parameter.

ie, I need all the objects saved with date 01/01/13 from 0:00 to 23:59.

The problem is if my local time is GMT-5 and I saved an object with date 01/01/13 20:00 (local time GMT-5), it will saved as 02/01/13 01:00, then when I query the objects of 01/01/13 appengine is not returning my object because its date is 02/01/13.

How can I handle this?

I´m using Objectify to manage datastore

Thx a lot

Since you have stored your objects in the database in UTC time (as is recommended practice), then you need to query in UTC as well.

So if you are interested in objects with times between 2013-01-01 00:00:00 -0500 and 2013-01-02 00:00:00 -0500 then you should query the times between 2012-12-31 19:00:00Z and 2013-01-01 19:00:00Z .

You can add an indexed integer property to your class, in which you additionally persist the date as YYYYMMDD with no hours. This way you can do a query using this property and retrieve the entitys you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM