Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeError: '>=' not supported between instances of 'builtin_function_or_method' and 'datetime.time'

I’m trying to compare two datetime.time values but I get this error:

File "c:\Users\xxxxxx\Desktop\pyfiche\code.py", line 33, in timeofweek
if (a.time >= d0.time() and a.time() <= d6.time()) or (a.time() >= d21.time() and a.time() <= d23.time()):
TypeError: ‘>=’ not supported between instances of ‘builtin_function_or_method’ and ‘datetime.time’

and this is my code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

def timeofweek(a):
    d6 = a.replace(hour=6, minute=0, second=0, microsecond=0) 
    d21 = a.replace(hour=21, minute=0, second=0, microsecond=0) 
    d0 = a.replace(hour=0, minute=0, second=0, microsecond=0) 
    d23 = a.replace(hour=23, minute=0, second=0, microsecond=0) 
    if a.weekday() in range(0,6):
        print(a.time(),type(a.time())) #for debugging and they are both Datetime.time
        print(d0.time(),type(d0.time())) #for debugging and they are both Datetime.time
        if (a.time() >= d6.time() and a.time() < d21.time()):
            return 1
        if (a.time() >= d0.time() and a.time() < d6.time()) or (a.time() >= d21.time() and a.time() <= d23.time()):
            return 2
    if a.weekday() == 6:
        if (a.time() >= d6.time() and a.time() <= d21.time()):
            return 2
        if (a.time >= d0.time() and a.time() <= d6.time()) or (a.time() >= d21.time() and a.time() <= d23.time()):
            return 3

I’m sure that d6, d21, d0, d23 are all the same type Datetime.time

the problem started when the input value changed from 24h to 12h format, but still when I print the value for debugging I still get the 24h format everytime.

>Solution :

you aren’t calling the .time() method for a in the second to last row. (You’re missing brackets)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading