手机版
你好,游客 登录 注册
背景:
阅读新闻

Django 查询时间段

[日期:2013-03-09] 来源:Linux社区  作者:forgetbook [字体:大 中 小]

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)

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款