【问题标题】:DATE COMPARISON in GOOGLE APP ENGINE DATASTORE / PYTHONGOOGLE APP ENGINE DATASTORE / PYTHON 中的日期比较
【发布时间】:2013-02-22 04:32:34
【问题描述】:

我正在尝试获取某个日期之后的记录。

我在代码中使用了以下内容:

qstr = "SELECT * FROM Comment where date > '"+str(max_date)+"' order by date desc limit 10"
comments = db.GqlQuery(qstr)

我有控制台日志我有 qStr 如下:

SELECT * FROM Comment where date > '2013-03-07 04:33:31' order by date desc limit 10"

但这不会产生任何记录(数据库中有记录)。

我也尝试过作为日期时间传递:

comments = db.GqlQuery("SELECT * FROM Comment where date > :1 order by date desc limit 10",
                                miscUtils._datetime_from_str(max_date))

这也不会产生任何结果。你能告诉我我做错了什么吗? (我正在使用以下代码将日期字符串转换为日期http://code.activestate.com/recipes/577135-parse-a-datetime-string-to-a-datetime-instance/

另外,我尝试在 App Engine 控制台中调试该语句,但无法这样做。

提前致谢

【问题讨论】:

  • Comment类中date属性的属性类型是什么?我的意思是,是StringProperty 还是DateTimeProperty
  • [看这里][1] 一些使用 ndb 和 datetime [1] 的日期查询:stackoverflow.com/a/15184526/784435
  • 我让它按如下方式工作:cmets = db.GqlQuery("select * from Comment where date > :1 order by date desc limit "+MAX_COMMENTS_PER_FETCH_STR, datetime.datetime.strptime(max_date, " %Y-%m-%d %H:%M:%S").date())

标签: google-app-engine python-2.7 google-cloud-datastore gql


【解决方案1】:

我让它工作如下:comments = db.GqlQuery("select * from Comment where date > :1 order by date desc limit "+MAX_COMMENTS_PER_FETCH_STR, datetime.datetime.strptime(max_date, "%Y-%m-%d %H:%M:%S").date())

感谢大家的帮助

【讨论】:

    猜你喜欢
    • 2021-01-02
    • 1970-01-01
    • 2014-04-10
    • 1970-01-01
    • 1970-01-01
    • 2014-03-12
    • 2012-07-09
    • 2015-10-08
    • 1970-01-01
    相关资源
    最近更新 更多