gpt4 book ai didi

python - 在 GqlQuery 的 where 子句中使用本地时间

转载 作者:行者123 更新时间:2023-11-30 23:58:34 25 4
gpt4 key购买 nike

我试图了解如何使用本地服务器时间来快速过滤 google appengine 上的结果。在我看来,应该有一种简单的方法可以使用 DATETIME(time.localtime()) 来执行此操作。

例如(其中“timestamp”的类型为 db.DateTimeProperty)...

q = db.GqlQuery("SELECT * FROM LiveData WHERE timestamp > DATETIME(:1)", time.localtime())

是否有 GqlQuery 和/或 python 构造可以让我通过一个方法调用来完成此操作?似乎我需要为 DATETIME() 参数创建字符串。

最佳答案

查询 DateTimeProperty 类型时不必创建字符串。试试这个:

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

关于python - 在 GqlQuery 的 where 子句中使用本地时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3007512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com