So I need to calculate 20 minutes before the last 10 mins. EG if it's currently 13:07, the time I need is 12:40
So from my research, I think I need to find the last 10th (or 0th) minute of the hour, then minus 20 minutes from that.
I found an answer to finding the next 10th minute
so I adjusted the code to find the last 10th minute, and then simply "- datetime.timedelta(minutes=20)"
import math
from datetime import datetime, timedelta
def ceil_dt(dt, delta):
return datetime.min + math.ceil((dt - datetime.min) / delta) * delta
print(ceil_dt(datetime(2012, 10, 25, 17, 2, 16), timedelta(minutes=-10))) - datetime.timedelta(minutes=20)
But it gives me the following exception
2012-10-25 17:00:00
Traceback (most recent call last):
File "F:/Pythong/test", line 7, in <module>
print(ceil_dt(datetime(2012, 10, 25, 17, 2, 16), timedelta(minutes=-10))) - datetime.timedelta(minutes=20)
AttributeError: type object 'datetime.datetime' has no attribute 'timedelta'
What I am doing wrong?