[Solved]-Django, actual month in queryset

35👍

http://docs.djangoproject.com/en/dev/ref/models/querysets/#month

You can

>>> import datetime
>>> today = datetime.date.today()
>>> MyModel.objects.filter(mydatefield__year=today.year,
                           mydatefield__month=today.month)

0👍

That’s if you are only interested in gettting the month:

import datetime

today = datetime.date.today()

months = ['zero','January','February','March','April','May','June','July','August','September','October','November','December']

current_month = months[today.month]

Leave a comment