开发者

Retrieving date from a datetime column in python/django

I have a column in my database which is named date... in this column i am storing a datetime value...n开发者_Python百科ow when i want to filter the table according to date value(only date and not datetime)..say i want to retrieve all coloums having a particular date..then how can i apply such filtering(i.e getting date out of datetime column)


For example, to match March 18, 2011:

queryset = MyModel.objects.filter(date__year=2011, date__month=3, date__day=18)

Django docs: http://docs.djangoproject.com/en/1.2/ref/models/querysets/#year


You can also do:

MyModel.objects.filter(date__gte=date, date__lt=date+datetime.timedelta(1))

Not sure which is faster, this or dappawit's solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜