Django 查询时间段
Django 查询时间段
大于某个时间
gt
now = datetime.datetime.now()
start = now – datetime.timedelta(hours=23, minutes=59, seconds=59)
a=yourobject.objects .filter(youdatetimcolumn__gt=start)
[, , ]
大于等于某个时间:
gte
查询的时候用
a=yourobject.objects .filter(youdatetimcolumn__gte=start)
语法
小于:
lt
a=yourobject.objects .filter(youdatetimcolumn__lt=start)
小于等于
lte
a=yourobject.objects .filter(youdatetimcolumn__lte=start)
查询时间段
range
start_date = datetime.date(2005, 1, 1)
end_date = datetime.date(2005, 3, 31)
Entry.objects.filter(pub_date__range=(start_date, end_date))
查询某年:
year
Entry.objects.filter(pub_date__year=2005)
查询某月:
month
Entry.objects.filter(pub_date__month=12)
某天
day
Entry.objects.filter(pub_date__day=3)
星期几
week_dayFo
Entry.objects.filter(pub_date__week_day=2)