[django]用日期来查询datetime类型字段
作者:互联网
有一个model的字段是
DateTimeField
,我现在要具体查询某一天date
的数据,应该怎么用orm来查询呢?
指定年月日
YourModel.objects.filter(datetime_published__year='2008',
datetime_published__month='03',
datetime_published__day='27')
- 1
- 2
- 3
字符串匹配
YourModel.objects.filter(your_datetime_field__startswith=datetime.date(2009,8,22))
- 1
字符串包含
Mymodel.objects.filter(date_time_field__contains=datetime.date(1986, 7, 28))
- 1
参考:How can I filter a date of a DateTimeField in Django?
标签:__,datetime,django,filter,objects,published,date,查询 来源: https://www.cnblogs.com/hichens/p/13037467.html