[PYTHON] Time calculation operator datetime timedelta

python


import datetime

now = datetime.datetime.now()

d = datetime.timedelta(weeks=-1)
d2 = datetime.timedelta(weeks=1)
d3 = datetime.timedelta(days=365)

print(now)
print(now + d)
print(now - d2)
print(now - d3)

Execution result


2020-02-26 11:24:59.726696
2020-02-19 11:24:59.726696
2020-02-19 11:24:59.726696
2019-02-26 11:24:59.726696

Recommended Posts

Time calculation operator datetime timedelta
Calculation time measurement using maf
Calculation of time series customer loyalty