python datetime get difference in hours code example
Example 1: get time between things python
>>> import datetime
>>> time1 = datetime.datetime.now()
>>> time2 = datetime.datetime.now()
>>> elapsedTime = time2 - time1
>>> elapsedTime
datetime.timedelta(0, 125, 749430)
>>> divmod(elapsedTime.total_seconds(), 60)
(2.0, 5.749430000000004)
Example 2: time difference between two datetime.time
dateTimeA = datetime.datetime.combine(datetime.date.today(), a)
dateTimeB = datetime.datetime.combine(datetime.date.today(), b)
dateTimeDifference = dateTimeA - dateTimeB
dateTimeDifferenceInHours = dateTimeDifference.total_seconds() / 3600