How to add months to a date (datetime object)?

Roy Smith roy at
Sun Mar 15 18:45:02 CET 2009

In article <49bd3ab8$0$510$bed64819 at>, tinnews at 

> I have a date in the form of a datetime object and I want to add (for
> example) three months to it.  At the moment I can't see any very
> obvious way of doing this.  I need something like:-
>     myDate =
>     inc = datetime.timedelta(months=3)
>     myDate += inc
> but, of course, timedelta doesn't know about months. I had a look at
> the calendar object but that didn't seem to help much.

Well, before you can "add three months" to something, you need to explain 
what that means.

What is Nov 29th plus 3 months?

What is Jan 31st plus 3 months?

Months are different lengths.  Asking to "add 3 months" is kind of like 
asking, "If I'm somewhere in the continental US (east of the Mississippi 
River) and move three states to the west, how many miles have I moved?"

More information about the Python-list mailing list