gpt4 book ai didi

python - 如何随时间过滤对象

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

假设我有一个简单的 Final 类,我想通过创建的字段过滤过去 2 天的结果,我该怎么做?当我填充最终类时,它有一个 utc 创建时间,但我需要该时间的差异,目前这符合我下面想要完成的操作,但我不确定如何在所有查询中获得差异元素?

class Final(db.Model):
name = db.StringProperty()
created = db.DateTimeProperty()

now = datetime.datetime.now()
##d = now - created
##if d.days > 2:
## I could loop along something like this but that would be too slow


results = Final.all()
results.filter('created =',##what do i do here?) ##would created >, and then now - 2days work?

最佳答案

我会尝试:

results.filter('created > ', now - datetime.timedelta(days=2))

关于python - 如何随时间过滤对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3272723/

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