歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Django 查詢時間段

Django 查詢時間段

日期:2017/3/1 10:00:26   编辑:Linux編程

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)

Copyright © Linux教程網 All Rights Reserved