Django 查询时间段 时间搜索 过滤

Django 查询时间段

1.大于某个时间

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

扫描二维码关注公众号,回复: 1772917 查看本文章

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)

猜你喜欢

转载自www.cnblogs.com/zhaoyingjie/p/9234442.html