Python : How to add month to December 2012 and get January 2013?

Posted by daydreamer on Stack Overflow See other posts from Stack Overflow or by daydreamer
Published on 2012-10-04T21:25:39Z Indexed on 2012/10/04 21:37 UTC
Read the original article Hit count: 164

Filed under:
|
|
>>> start_date = date(1983, 11, 23)
>>> start_date.replace(month=start_date.month+1)
datetime.date(1983, 12, 23)

This works until the month is <=11, as soon as I do

>>> start_date = date(1983, 12, 23)
>>> start_date.replace(month=start_date.month+1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: month must be in 1..12

How can I keep adding months which increments the year when new month is added to December?

© Stack Overflow or respective owner

Related posts about python

Related posts about date