0

I have 2 time values which have the type datetime.time. I want to find their difference. The obvious thing to do is t1 - t2, but this doesn't work. It works for objects of type datetime.datetime but not for datetime.time. So what is the best way to do this?

Thornily
  • 386
  • 1
  • 9
  • 1
    What is the difference between `23:55` and `00:05`? – tobias_k Sep 15 '21 at 15:30
  • I dont understand where you got 23:55 and 00:05 – Thornily Sep 15 '21 at 15:31
  • Just a hypothetical example. So what would you see as the difference there? 10 Minutes, or 23 hours and 45 minutes? Just to point out the ambiguity when it comes to differences of pure times without dates, which is probably the reason it is not implemented directly in the library. – tobias_k Sep 15 '21 at 15:32
  • @PythonIsTriggered It's just an example to point out that there is more than one way of calculating the difference. – MisterMiyagi Sep 15 '21 at 15:32
  • Of course, if you know which time is the later one, that ambiguity can be resolved (as long as there's not more than one day in between), but even then you have to be careful, e.g. add 24h if the difference is negative (none of the linked answers seem to do that) – tobias_k Sep 15 '21 at 15:36

0 Answers0