-
-
Save diptangsu/7c679e1785e2d5d8203693a7d64a47c9 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.combine(timezone.now().date(), datetime.today().time().min) | |
today_max = datetime.combine(timezone.now().date(), datetime.today().time().max) | |
objetcs_for_today = MyModel.objects.filter(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 one worked for me: