I need to create a DateTime object that represents the current time minus 15 minutes.
If you are using time.time()
and wants timestamp as output
Simply use
CONSTANT_SECONDS = 900 # time in seconds (900 seconds = 15 min)
current_time = int(time.time())
time_before_15_min = current_time - CONSTANT_SECONDS
You can change 900 seconds as per your required time.
from datetime import timedelta
datetime.datetime.now() - datetime.timedelta(0, 900)
Actually 900 is in seconds. Which is equal to 15 minutes. `15*60 = 900`
import datetime and then the magic timedelta stuff:
In [63]: datetime.datetime.now()
Out[63]: datetime.datetime(2010, 12, 27, 14, 39, 19, 700401)
In [64]: datetime.datetime.now() - datetime.timedelta(minutes=15)
Out[64]: datetime.datetime(2010, 12, 27, 14, 24, 21, 684435)