Created
December 26, 2012 16:29
-
-
Save tsileo/4381277 to your computer and use it in GitHub Desktop.
add_months
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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