gpt4 book ai didi

google-app-engine - GQL 按日期选择

转载 作者:太空宇宙 更新时间:2023-11-03 15:31:27 25 4
gpt4 key购买 nike

我有这个模型:

class Entry(db.Model):
title = db.StringProperty()
url = db.URLProperty()
date = db.DateTimeProperty(auto_now=True)
image = db.URLProperty()
weight = db.IntegerProperty()
category = db.StringProperty()
desc = db.TextProperty()

我每天都有很多条目,如何使用 GGL 只选择今天的条目?因为这样的查询不会返回任何结果(但我知道有结果):

SELECT * FROM Entry WHERE category = 'news' and date = '2012-03-12' ORDER BY weight DESC

最佳答案

它不是保存为字符串,而是保存为类似日期时间的对象。

The right-hand side of a comparison can be one of the following:

  • a datetime, date, or time literal, with either numeric values or a string representation, in the following forms:

    DATETIME(year, month, day, hour, minute, second)
    DATETIME('YYYY-MM-DD HH:MM:SS')
    DATE(year, month, day)
    DATE('YYYY-MM-DD')
    TIME(hour, minute, second)
    TIME('HH:MM:SS')

http://code.google.com/appengine/docs/python/datastore/gqlreference.html

所以在您的示例中,使用其中任何一个。

date = DATE('2012-03-12')
date = DATE(2012,03,12)

对于datetime,时间默认设置为00:00,所以相等比较会失败所以你必须使用>来比较

SELECT * FROM Entry WHERE date > DATETIME(yyyy,mm,dd)

关于google-app-engine - GQL 按日期选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9700579/

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