I have two datetime.time objects and I want to calculate the difference in hours between them. For example
a = datetime.time(22,00,00)
b = datetime.time(18,00,00)
I would like to be able to subtract these so that it gives me the value 4.
I have two datetime.time objects and I want to calculate the difference in hours between them. For example
a = datetime.time(22,00,00)
b = datetime.time(18,00,00)
I would like to be able to subtract these so that it gives me the value 4.
I got my result from this problem:
but in series that wont work:
This is how I did
output: 4.0
To calculate the difference, you have to convert the
datetime.time
object to adatetime.datetime
object. Then when you subtract, you get atimedelta
object. In order to find out how many hours thetimedelta
object is, you have to find the total seconds and divide it by3600
.