如何在Django中按小时过滤DateTime字段?

问题描述 投票:0回答:1

我有Django 1.8和Python 2.7,我需要每小时获得订单

该字段是DateTimeField

close_date = models.DateTimeField(null=True, blank=True)

我做简单的循环:

for hour in xrange(0, 24):
    orders = Order.objects.filter(close_date__hour=hour)

但它不会过滤。

python django
1个回答
0
投票

你可以试试:

Order.objects.filter(close_date__regex = 'HH:00')(close_date__contains = 'HH:00')

因为也许django 1.8只支持年,月,日,周日。

© www.soinside.com 2019 - 2024. All rights reserved.