开发者

Using localtime in a where clause for GqlQuery

开发者 https://www.devze.com 2023-01-02 17:12 出处:网络
I\'m trying to understand how I can use the local server time to quickly filter results on google appengine. It seems to me that there should be a simple way of doing this using DATETIME(time.localtim

I'm trying to understand how I can use the local server time to quickly filter results on google appengine. It seems to me that there should be a simple way of doing this using DATETIME(time.localtime()).

For example (where 'timestamp' is of type db.DateTimeProperty)...

q = db.GqlQuery("开发者_JAVA技巧SELECT * FROM LiveData WHERE timestamp > DATETIME(:1)", time.localtime())

Is there a GqlQuery and/or python construct that lets me do this with one method call? It seems as though I need to create strings for DATETIME() parameters.


You do not have to create strings when querying DateTimeProperty types. Try this:

import datetime
q = db.GqlQuery("SELECT * FROM LiveData WHERE timestamp > :1", datetime.datetime.now())
0

精彩评论

暂无评论...
验证码 换一张
取 消