NIKHIL RANE
NIKHIL RANE

Reputation: 4092

Django: filter datetime in date on date range

I'm trying to filter the query set on between two dates. here is my views.py

week = (startDate, endDate)
Student.objects.filter(created__range=week)

but I want filter on only date

i'd like to match the month, day, year exactly, not the time.

expected output is filter queryset between startDate and endDate

Upvotes: 1

Views: 1927

Answers (1)

catavaran
catavaran

Reputation: 45595

Replace the __range lookup with __gte/__lt combination.

Student.objects.filter(created__gte=startDate,
                       created__lt=endDate + datetime.timedelta(days=1))

Upvotes: 4

Related Questions