I need to use the output from "retention" to add in the line: expiration = retention, // date/time, in iso8601 format (type: string)

from datetime import datetime, timedelta

# get current datetime
today = datetime.now()

# printing today date
print('Today Date:', str(today))

# Get current ISO 8601 datetime in string format
iso_date = today.isoformat()

# printing iso_date
print('ISO Date:', str(iso_date))

# Calculating retention
# Retention = 7 days from current date

retention = iso_date + timedelta(days=7)

# printing retention date
print('Retention:', str(retention))

I use print to check if the output is correct but i’m getting this error:
Today Date: 2023-09-25 01:47:52.056294
ISO Date:2023-09-25T01:47:52.056294
Traceback (most recent call last):
File “C:\Users\jaysen\Desktop\retention.py”,line 17, in
retention = iso_date + timedelta(days=7)
~^~~~~~~~~~~
TypeError: can only concatenate str (not “datetime.timedelta”) to str
How can I resolve this?

Can you add timedelta + today?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.