Why can’t subtract two time objects? For example, 12:00 – 11:00 = 1:00
from datetime import time
time(12,00) - time(11,00) # -> timedelta(hours=1)
It seems that datetime.time.__sub__ is missing
TypeError: unsupported operand type(s) for -: 'datetime.time' and 'datetime.time'
do you know why?
The
timeobjects have no date, so for example, the12:00might be (say) on a Wed and the11:00on the preceding Tue, making the difference 25 hours, not one (any multiple of 24 might be added or subtracted). If you know they’re actually on the same date, just apply any arbitrary date to each of them (making twodatetimeobjects) and then you’ll be able to subtract them. E.g.: