Time and conditional statement is not working in python?
Question: What the purpose of this file is for, is to switch a Boolean to false when the
time (EST) is between 8 AM-11 PM.

    
    
    import time as t
    from datetime import datetime
    while True:
    t.sleep(1)
    current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    current_hour = datetime.now().strftime('%H')
    print current_hour
    if 23 > current_hour:
        print 'Sleep mode activated (1)'
        sleep_mode = True
    elif current_hour < 7:
        print 'Sleep mode activied (2)'
        sleep_mode = True
    else:
        sleep_mode = False
    

The problem, however is here:

    
    
    if 23 > current_hour:
        print 'Sleep mode activated (1)'
        sleep_mode = True
    

It returns true even if I change '23' to an unrealistic number, or a time in
which is MUCH greater than the current time.

I've also tested to make sure that its working in EST; which it is. I don't
know if theres something wrong with the if statement or something. Please
help?


Answer: You should never do this:

    
    
    current_hour = datetime.now().strftime('%H')
    

If you want the current hour, just use:

    
    
    current_hour = datetime.now().hour
    

You are converting a `datetime` to a string, then extracting part of that
string and trying to compare it to a different data type. **Don't. Do. That.**
Python's [datetime](https://docs.python.org/2/library/datetime.html) module
has wonderful properties, like
[hour](https://docs.python.org/2/library/datetime.html#datetime.datetime.hour)
\- just use them.

