Search code examples
pythonpython-datetime

convert datetime.date(hh) to int python django


how to convert DateTime.time to int?...

I have datetime.time(23) that 23 representatives as hours.

minutes and second will be ignore, just take the hours.

I need to convert it to int, so example:

overtime_count = datetime.time(23) - datetime.time(14)

overtime_count = 9

i want that 9 can multiple by int. example 9 * 20 = 180


Solution

  • You could do .hour:

    print(datetime.time(23).hour)
    # 23
    

    To calculate overtime:

    overtime_count = datetime.time(23).hour - datetime.time(14).hour
    # 9