Last active
April 13, 2020 11:00
-
-
Save cansadadeserfeliz/3e5107b11d19ac62a2ed to your computer and use it in GitHub Desktop.
Django: filter DatetimeField by today (max and min time)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# source: http://stackoverflow.com/questions/1317714/how-can-i-filter-a-date-of-a-datetimefield-in-django | |
from django.utils import timezone | |
today_min = datetime.datetime.combine(timezone.now().date(), datetime.time.min) | |
today_max = datetime.datetime.combine(timezone.now().date(), datetime.time.max) | |
MyModel.objects.get(date__range=(today_min, today_max)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This piece of code wasn't working for me today. So I forked this and made a few changes.