Skip to content

Instantly share code, notes, and snippets.

@aminami1127
Created June 14, 2015 03:15
Show Gist options
  • Save aminami1127/002847c48cab508c9ccd to your computer and use it in GitHub Desktop.
Save aminami1127/002847c48cab508c9ccd to your computer and use it in GitHub Desktop.
Calculate weeks or months
from dateutil.relativedelta import relativedelta
from datetime import datetime
today = datetime.today()
today.strftime('%Y-%m-%d')
# '2015-06-14'
next_week = today + relativedelta(weeks=1)
next_week.strftime('%Y-%m-%d')
# '2015-06-21'
next_month = today + relativedelta(months=1)
next_month.strftime('%Y-%m-%d')
# '2015-07-14'
from calendar import monthrange
lastday_of_month = monthrange(2015, 6)[1]
lastday_of_month
# 30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment