[Python] subtract two times in python

Discussão em 'Python' iniciado por Stack, Abril 27, 2025.

  1. Stack

    Stack Membro Participativo

    I have two datetime.time values, exit and enter and I want to do something like:

    duration = exit - enter


    However, I get this error:


    TypeError: unsupported operand type(s) for -: 'datetime.time' and 'datetime.time
    ​

    How do I do this correctly? One possible solution is converting the time variables to datetime variables and then subtruct, but I'm sure you guys must have a better and cleaner way.

    Continue reading...

Compartilhe esta Página