5

I have this code, but I got an error and could not find a soulution to the problem. I was trying to get a time and then plus i hour becuase i live in europe.

Here is my code: plus_one_hour = "21:00:00" + timedelta(hours=2)

And the error: TypeError: cannot concatenate 'str' and 'datetime.timedelta' objects

1 Answer 1

12

Convert your string to datetime object.

Ex:

import datetime
plus_one_hour = datetime.datetime.strptime("21:00:00", "%H:%M:%S") + datetime.timedelta(hours=2)
print(plus_one_hour.strftime("%H:%M:%S"))

Output:

23:00:00
Sign up to request clarification or add additional context in comments.

2 Comments

Wow... Thanks for the code, i dont know if it was me trying to print it out or your code. But anyway thanks for the help :)
i try to this script but not work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.