Manipulating dates in the datastore
I've recently been playing around with Google's AppEngine and I seem to have gotten stuck. I'm trying to create a query that selects posts that are before a certain date (in this case, the date is now - 1 day). I've tried a few different methods in order to accomplish this, but none have worked. One o开发者_如何转开发f which involved converting all the dates to UNIX time and running a query like this:
db.GqlQuery("SELECT __key__ FROM Post WHERE date-84600 < %s LIMIT 10, ORDER BY date DESC" % time.time())
But after trying that, I got a syntax error which told me GQL didn't have support for operations such as subtracting in the queries.
Does anyone have any idea as to how I could accomplish this?
Thanks in advance
What happens if you build your query using methods?
query = Post.all()
query.filter('date < ', datetime.datetime - 84600)
results = query.fetch(limit=10)
You need to move the math outside of the query:
db.GqlQuery("SELECT __key__ FROM Post WHERE date < :1 LIMIT 10, ORDER BY date DESC", (time.time() - 84600))
精彩评论