How can I filter a date of a DateTimeField in Django?

datetime, django, django-queryset, filter, python

Solution

Such lookups are implemented in `django.views.generic.date_based` as follows:

{'date_time_field__range': (datetime.datetime.combine(date, datetime.time.min),
                            datetime.datetime.combine(date, datetime.time.max))} 

Because it is quite verbose there are plans to improve the syntax using `__date` operator. Check "#9596 Comparing a DateTimeField to a date is too hard" for more details.

Problem

I am trying to filter a `DateTimeField` comparing with a date. I mean: ``` MyObject.objects.filter(datetime_attr=datetime.date(2009,8,22)) ``` I get an empty queryset list as an answer because (I think) I am not considering time, but I want "any time". Is there an easy way in Django for doing this? I have the time in the datetime setted, it is not `00:00`.

Original source

Related problems