Question

I'm trying to filter Performance by start_time hour using Django 1.6. In the console I see :

>>> Performance.objects.first().start_time
datetime.datetime(2014, 4, 6, 11, 0, tzinfo=<UTC>)
>>> Performance.objects.first().start_time.hour
11

But then, from the docs at https://docs.djangoproject.com/en/1.6/ref/models/querysets/#hour:

>>> Performance.objects.filter(start_time__hour=11)
[]

How can I filter by hour? Very similar to this (currently unanswered) question: Django ORM: filter by hour range.

From models.py:

class Performance(models.Model):
    start_time = models.DateTimeField(db_index=True)
    end_time = models.DateTimeField(default=None, blank=True, null=True)
...
Was it helpful?

Solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top