Add month value in python

Tuesday, August 6, 2013

Subscribe for future Changes.. Explanation soon..

This is short and sweet method to add a month in a date using relativedelta.
from datetime import datetime
from dateutil.relativedelta import relativedelta

date_after_month = datetime.today()+ relativedelta(months=1)
print 'Today: ',datetime.today().strftime('%d/%m/%Y')
print 'After Month:', date_after_month.strftime('%d/%m/%Y')
Output:
Today: 01/03/2013
After Month: 01/04/2013

No comments:

Post a Comment