Reputation: 109
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?
Upvotes: 1
Views: 2185
Reputation: 996
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.
Upvotes: 4