If you want to have a more general solution to this problem, for example. adding days, months and years mixed with one date:
import time, datetime, calendar def upcount(dt, years=0, months=0, **kwargs): if months: total_months = dt.month + months month_years, months = divmod(total_months, 12) if months == 0: month_years -= 1 months = 12 years += month_years else: months = dt.month years = dt.year + years try: dt = dt.replace(year=years, month=months) except ValueError:
source share