How to filter by date / time in Google App Engine datastore using GoLang

I am working on a golang hond server on Google App Engine. I have an Entity with a name Recruit

that has a property

UpdatedAt time.Time `datastore:"updated_at"`

      

I want to request recruits for their updated time. My first instinct is to use filter .

query = datastore.NewQuery("Recruit").Filter("updated_at <=", updatedAt)

      

where updatedAt is a string. I've tried forms 2014-08-28 01:53:19

and 2014-08-28T01:53:19.00618Z

(the first is the form's time.Time property takes in the datastore, and the last is how it gets propagated to JSON.)

When I call the request with <=

, all Recruit objects are returned. When called >=

, null is returned. I'm pretty sure I'm testing time from the middle of the dataset.

When I test on console.developers.google.com console filters are supported a date and time

after/before

, but trying to replace <=

with after

results in an error.

Anyone could filter queries by date or time?

+3


source to share


1 answer


Try using updateAt of type time.Time instead of string

Below is a snippet of how I managed to filter requests by time:

My property:

TimeStamp time.Time

      



My request:

timeNow := time.Now()
time1hr := timeNow.Add(-59*time.Minute)
q := datastore.NewQuery("Recruit").Filter("TimeStamp <=", time1hr)

      

This code will give me all objects until time1.

+2


source







All Articles