I am working with a date format that looks like this:
2023-04-25T16:00:00+00:00
I want to add 5 days to the current_date and return the same format as above
I tried this:
from datetime import datetime, timedelta
today = datetime.now()
iso_date = today.isoformat()
iso_date += timedelta(days=5)
which throws:
TypeError: can only concatenate str(not "datetime.timedelta") to str
>Solution :
The return value of isoformat() is a string. Your timedelta should be added to the Date object, not the string:
today = datetime.now()
today += timedelta(days=5)
iso_date = today.isoformat()