mercredi 30 mars 2016

if conditions on datetime - Pyhton [duplicate]

This question already has an answer here:

I'm trying to run some code at certain times of the day, I understand datetime is an object, new to python and don't understand why working with dates have to be such a pain.

t = time.strftime("%H%M")
print(t) # this displays 1809

if 2359 > t > 900:
    # if condition not meet

However when I set t as an int my if condition is meet. I did see a couple of solutions on here but none seemed to actually work.

The following code using str() seems to work but I would think there is a better way to do this

t = str(time.strftime("%H%M"))
print(t) # this displays 1809

if "2359" > t > "0900":
    # if condition not meet

Aucun commentaire:

Enregistrer un commentaire