1>>> import datetime
2>>> time1 = datetime.datetime.now()
3>>> time2 = datetime.datetime.now() # waited a few minutes before pressing enter
4>>> elapsedTime = time2 - time1
5>>> elapsedTime
6datetime.timedelta(0, 125, 749430)
7>>> divmod(elapsedTime.total_seconds(), 60)
8(2.0, 5.749430000000004) # divmod returns quotient and remainder
9# 2 minutes, 5.74943 seconds
10
1# Create datetime objects for each time (a and b)
2dateTimeA = datetime.datetime.combine(datetime.date.today(), a)
3dateTimeB = datetime.datetime.combine(datetime.date.today(), b)
4# Get the difference between datetimes (as timedelta)
5dateTimeDifference = dateTimeA - dateTimeB
6# Divide difference in seconds by number of seconds in hour (3600)
7dateTimeDifferenceInHours = dateTimeDifference.total_seconds() / 3600
8