weiqure
weiqure

Reputation: 3235

How to query for a row with a specific DateTime value using GQL?

I tried just using the date's string representation but it didn't work (i.e. no results):

gql = "SELECT * from Shout where when='2010-11-05 16:57:45.675612'"

This is my Shout class:

class Shout(db.Model):
   message= db.StringProperty(required=True)
   when = db.DateTimeProperty(auto_now_add=True)
   who = db.StringProperty()

Upvotes: 0

Views: 1020

Answers (1)

mechanical_meat
mechanical_meat

Reputation: 169334

gql = "SELECT * FROM Shout WHERE when = DATETIME('2010-11-05 16:57:45')"

Per documentation, use the following for date/time literals:

  • DATETIME() with timestamps,
  • DATE() with dates,
  • TIME() with times

An alternative syntax is:

SELECT * FROM Shout WHERE when = DATETIME(2010,11,5,16,57,45)

Upvotes: 1

Related Questions