73481/how-do-i-filter-query-objects-by-date-range-in-django
I've got a field in one model like:
class Sample(models.Model): date = fields.DateField(auto_now=False)
Now, I need to filter the objects by a date range.
How do I filter all the objects that have a date between 1-Jan-2020 and 31-Jan-2020?
Hello @kartik,
Use
Sample.objects.filter(date__range=["2020-01-01", "2020-01-31"])
Or if you are just trying to filter month wise:
Sample.objects.filter(date__year='2020', date__month='01')
Hope it helps!!
Thank You!!
with open(fname) as f: content = f.readlines() # you ...READ MORE
can you tell me the procedure for ...READ MORE
Use random.uniform(a, b): Returns a random floating point ...READ MORE
Delete the List and its element: We have ...READ MORE
Hi, there is only that way and ...READ MORE
Hi all, with regard to the above ...READ MORE
Hello @kartik, To turn off foreign key constraint ...READ MORE
Hello @kartik, Let's say you have this important ...READ MORE
Hello @KARTIK, Just add an extra template tag ...READ MORE
Hii, Django does not support free group by ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.