Skip to content
Advertisement

How do I filter query objects by date range in Django?

I’ve got a field in one model like:

JavaScript

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-2011 and 31-Jan-2011?

Advertisement

Answer

Use

JavaScript

Or if you are just trying to filter month wise:

JavaScript

Edit

As Bernhard Vallant said, if you want a queryset which excludes the specified range ends you should consider his solution, which utilizes gt/lt (greater-than/less-than).

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement