Skip to content

Instantly share code, notes, and snippets.

@nimasmi
Created October 17, 2017 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nimasmi/59ec373c09d9a6c635787ba2ec791395 to your computer and use it in GitHub Desktop.
Save nimasmi/59ec373c09d9a6c635787ba2ec791395 to your computer and use it in GitHub Desktop.
List today, start of next month, start of 2 months hence, etc. up to start of 12 months hence
from django.utils.timezone import now
from dateutil.rrule import MONTHLY, rrule
def get_start_date_choices():
today = now().date()
choices = [(today, "Now")]
for start_date in rrule(MONTHLY, count=12, dtstart=today,
bymonthday=1):
if start_date.date().year == today.year:
date_format = "%B"
else:
date_format = "%B %Y"
choices.append((start_date.date().isoformat(), start_date.strftime(date_format)))
return choices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment