Filtering a complete date in django?
-
10-07-2019 - |
Question
There are several filter methods for dates (year,month,day). If I want to match a full date, say 2008/10/18, is there a better way than this:
Entry.objects.filter(pub_date__year=2008).filter(pub_date__month=10).filter(pub_date__day=18)
Solution
How about using a datetime object. For example:
from datetime import datetime
Entry.objects.filter(pub_date=datetime(2008, 10, 18))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow