Computer >> Computer tutorials >  >> Programming >> Python

How do I calculate the date six months from the current date using the datetime Python module?


You can use the timedelta function from datetime module to achieve this. For example,

>>> import datetime
>>> today = datetime.date.today()
>>> print today
2017-09-12
>>> six_months_later = today + datetime.timedelta(30*6)
>>> print six_months_later
2018-03-11