-2

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.

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

0

1 Answer 1

1

You can use ** to pass keyword arguments and do this

Time_Unit = "days"
Time_Increment = 1

Time2 = Time1 + timedelta(**{Time_Unit:Time_Increment})
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.