Python: How to get the sum of timedelta?
Eg. I just got a lot of timedelta object, and now I want the sum. That's it!
To add timedeltas you can use the builtin operator +
:
result = timedelta1 + timedelta2
To add a lot of timedeltas you can use sum:
result = sum(timedeltas, datetime.timedelta())
Or reduce:
import operator
result = reduce(operator.add, timedeltas)