views:

72

answers:

2
right_now = datetime.datetime.now()
one_hour_before = ?????

How can I use right_now to get one_hour_before?

+7  A: 
right_now = datetime.datetime.now()
one_hour_before = right_now - datetime.timedelta(hours=1)
paprika
+1  A: 

You need to use datetime.timedelta like so:

right_now = datetime.datetime.now()
one_hour_before = right_now - datetime.timedelta(hours = 1)
Rishabh Manocha