0

How do I subtract a starting time in hours and minutes (e.g. 2:30) from an ending time in hours and minutes (e.g. 5:15) in Python?

lengthOfDay=datetime(endh,endm) - datetime.timedelta(starth,startm)
martineau
  • 119,623
  • 25
  • 170
  • 301
  • 1
    Was there a particular problem with the code you have shown? – mkrieger1 Feb 08 '22 at 23:07
  • If you subtract two `datetime` values, you get a `timedelta`. If you subtract a `timedelta` from a `datetime`, you get a `datetime`. What you've displayed as an example is the latter, but you asked for the former. – Mark Tolonen Feb 08 '22 at 23:42

0 Answers0