Python: 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

 stackoverflow.com/questions/42950/get-last-day-of-the-month-in-python

Leave a Reply

Your email address will not be published. Required fields are marked *