首页 > 其他 > 详细

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

时间:2018-06-27 16:08:35      阅读:372      评论:0      收藏:0      [点我收藏+]

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

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)

 

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

原文:https://www.cnblogs.com/zhaoyingjie/p/9234442.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!