Add a month

Raymond Hettinger python at rcn.com
Fri Feb 17 06:06:43 EST 2006


[novin01 at gmail.com]
> Hi, this is probably a really simple question but...
> How do you add a month to a datetime date in python? It would be nice
> if  you could do something like:
>
> d = datetime.date(2006,2,17)
> dm = datetime.timedelta(months=1)
> d_new = d + dm
>
> but timedelta doesn't have a 'months' setting. Am I missing some easy
> method or do I have to code a work around myself??

You need to code you own version.

It was not included with datetime.timedelta() because the definition is
ambiguous (i.e. what date is one month after Jan 30th?).


Raymond




More information about the Python-list mailing list