Add a month

Daniel Dittmar daniel.dittmar at sap.corp
Fri Feb 17 06:52:48 EST 2006


Fredrik Lundh wrote:
> novin01 at gmail.comn wrote:
> 
>> 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??
> 
> what do you expect d_new to be after the operation ?  if the answer
> is date(2006,3,17), what's date(2006,1,31) plus one month?

Traceback (most recent call last):
   File "<stdin>", line 1, in ?
ValueError: date domain error

in analogy to math.sqrt (-2)

Daniel



More information about the Python-list mailing list