[Django]-How to get hour and minute integers from TimeField in Django?

3👍

It’s TimeField, as you said. Let’s have a look at TimeField docs: A time, represented in Python by a datetime.time instance, so you shouldn’t use strptime on self.time. I think that your code should looks like:

def late(self):
    return self.time.hour > 9

Same for minute

0👍

You should not use tm_hour and tm_min but hour and minute respectively.

def late(self):
    t = strptime(self.time, "%H:%M")
    return t.hour > 9

Leave a comment