App selection based on timestamp

I can't pick something based on timestamp. The behavior is a little strange and the <and = symbols don't seem to mean what I expect them to be.

"" "A site message" ""
class Message (db.Model):
  # from / to / a few other fields
  subject = db.StringProperty ()
  body = db.Text ()

  # this is the field i'm trying to use
  sent = db.DateTimeProperty (auto_now_add = True)

When I write GQL queries like

select * from Message where sent = '2009-09-14 01: 00: 02.648000'

(there is a message with EXACTLY that the timestamp is in the data store)

it returns nothing to me.

If i try

select * from Message where sent <'2009-09-14 01: 00: 02.648000'

It just gives me everything. When I try to use the> sign, it just doesn't give me any more.

What's going on here and how do I select based on the timestamp?

+2


source to share


1 answer


Do NOT use strings to "stand" for datetimes! It just won't work ...



See docs : DateTimeProperty

matches datetime.datetime . import datetime

, convert your favorite strings to instances datetime.datetime

(by calling a method, for example strptime

), use TOSA instances to compare - and of course, live happily ever after! -)

+5


source







All Articles