Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One hour difference in Python

I have a datetime.datetime property var. I would like to know if it is less than one hour of the current time. Something like

var.hour<datetime.datetime.today().hour - 1

Problem with the above syntax is that

datetime.datetime.today().hour

returns a number such as "10" and it is not really a date comparation but more of a numbers comparation.

What is the correct syntax?

Thanks!

Joel

like image 300
Joel Avatar asked Apr 03 '10 14:04

Joel


1 Answers

Use datetime.timedelta.

var < datetime.datetime.today() - datetime.timedelta(hours=1)
like image 161
Daniel Roseman Avatar answered Sep 28 '22 16:09

Daniel Roseman