Python: Timedelta Unit Argument as a Variable
15:01 06 Nov 2025

Is it possible to have the units argument for the timedelta function be defined by a variable?

To elaborate, is this possible?

Time_Unit = "days"
Time_Increment = 1

Time2 = Time1 + timedelta(Time_Unit=Time_Increment)

Where Time1 and Time2 will be in Days. But if I change Time_Unit = "seconds" and Time_Increment = 25, How can I do that?

The time format I'm using is ISO 8601 (YYYY-MM-DDTHH:mm:ssZ), so Time1 and Time2 can be easily incremented in seconds, minutes, hours, etc.

If this isn't clear, please let me know.

I followed the manual, but couldn't find an answer.

Thanks.

python datetime variables timedelta