[django]用日期来查询datetime类型字段

 

有一个model的字段是 DateTimeField,我现在要具体查询某一天date的数据,应该怎么用orm来查询呢?

指定年月日

YourModel.objects.filter(datetime_published__year='2008', 
                         datetime_published__month='03', 
                         datetime_published__day='27')

 

字符串匹配

YourModel.objects.filter(your_datetime_field__startswith=datetime.date(2009,8,22))

 

字符串包含

Mymodel.objects.filter(date_time_field__contains=datetime.date(1986, 7, 28))

 

posted on 2018-09-18 16:23  星河赵  阅读(948)  评论(0编辑  收藏  举报

导航