Skip to content

Instantly share code, notes, and snippets.

@AllanLRH
Created August 13, 2014 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AllanLRH/b233623d75934468cec8 to your computer and use it in GitHub Desktop.
Save AllanLRH/b233623d75934468cec8 to your computer and use it in GitHub Desktop.
Calculate time difference from strings formattet HH:MM:SS, using datetime module.
from datetime import datetime
def timeDifference(t0, t1):
FMT = '%H:%M:%S'
timeDelta = datetime.strptime(t1, FMT) - datetime.strptime(t0, FMT)
return timeDelta
if __name__ == '__main__':
t0 = '08:00:00'
t1 = '16:00:00'
delta_t = timeDifference(t0, t1)
print(delta_t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment