Check out the python-dateutil <http://labix.org/python-dateutil> module (not in the standard lib, but available via pip and easy_install). It makes calculating time deltas easy.
Anyways, try something like this: #!/usr/bin/env python from datetime import datetime from dateutil.relativedelta import relativedelta employees = {} now = datetime.now() ranges = [(0, 3), (3, 6), (6, 12), (12, 24)] for (a, b) in ranges: start_date = now - relativedelta(months=b) end_date = now - relativedelta(months=a) employees[(a, b)] = Employees.objects.filter( doj_date__range=(start_date, end_date)) On Mon, May 23, 2011 at 3:45 PM, sushanth Reddy <sushant...@gmail.com>wrote: > Hi, > > How to get model filter on date ranges. In my project using employee doj, i > need to deign a table. like employee who have joined less than three months > , 3-6month, 6-12 months, 12-24 months. > > Depart < 3month 3-6months 6-12months 12-24months > ----------------------------------------- ---- ----- > > A dep 4 6 6 8 > > ------------------------------------------------------ > > How to do this filter in django. > > I have gone through this link ,but its confusing . > > http://www.nerdydork.com/django-filter-model-on-date-range.html > > Thanks in Advance > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.