How do I add a month to my date object in datetime? Python

Viewed 6405

I need to create a day variable which will store the current date, and I need another variable which will store the deadline(day + 1 month), but I seem to be doing something wrong.

import datetime

day = datetime.date.today()
deadline = datetime.date.today()
deadline.month += 1

print(day)
print(deadline)
2 Answers

You could try importing python-dateutil and use relativedelta to achieve what you want. You could refer to this answer for more info

deadline = day + relativedelta(months=1)
Related