1

I have tons of timestamp strings like this one 2017-04-18 05:03:40.966084 and the script needs to add seconds to the timestamp. I have been trying to turn the string into a legit timestamp object and then add seconds to it with timedelta but for some reason it isn't working.

This is what I have so far:

duration = "150.100"
timestamp = datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S.%f")
timestamp_e = timestamp+timedelta(seconds=duration)

Am I going at this the right way?

1
  • What is not working? Do you get an error, is the result semantically wrong, or does something else happen? Commented Nov 16, 2017 at 8:09

1 Answer 1

4

Yes timedelta is a good way to adjust a timestamp. However note that your duration variable is a string. As per the documentation it should be an integer or float:

All arguments are optional and default to 0. Arguments may be integers or floats, and may be positive or negative.

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

Comments

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.