Skip to content

Instantly share code, notes, and snippets.

@tsileo
Created December 26, 2012 16:29
Show Gist options
  • Save tsileo/4381277 to your computer and use it in GitHub Desktop.
Save tsileo/4381277 to your computer and use it in GitHub Desktop.
add_months
import calendar
from datetime import date
def add_months(sourcedate,months):
month = sourcedate.month - 1 + months
year = sourcedate.year + month / 12
month = month % 12 + 1
day = min(sourcedate.day,calendar.monthrange(year,month)[1])
return date(year,month,day)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment