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!!
readline function help to read line in ...READ MORE
can you tell me the procedure for ...READ MORE
Use random.uniform(a, b): Returns a random floating point ...READ MORE
1886 Use del and specify the index of the element ...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
Already have an account? Sign in.