Menu Close

How to filter a date of a DateTimeField in Python Django?

To filter a date of a DateTimeField in Python Django, we can use filter with a datetime.

For instance, we write

YourModel.objects.filter(datetime_published=datetime(2018, 03, 27))

to call filter to return the results with the datetime_published field set to 2018-03-27.

Posted in Python, Python Answers