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


I am trying to filter a DateTimeField comparing with a date. I mean:


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.

12/19/2015 8:54:10 AM

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.

9/26/2015 3:12:43 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow