Skip to content

Instantly share code, notes, and snippets.

@sebastian-berlin-wmse
Created April 11, 2025 08:31
Show Gist options
  • Save sebastian-berlin-wmse/5bf884e9e2771b6a713fdcf9d1278867 to your computer and use it in GitHub Desktop.
Save sebastian-berlin-wmse/5bf884e9e2771b6a713fdcf9d1278867 to your computer and use it in GitHub Desktop.
Calculate difference between two timestamps
#! /usr/bin/env python
"""Calculate time difference between two timestamps
First argument is the "from" time and second is the "to" time. Format should
be anything that works with `datetime.fromisoformat`
(https://docs.python.org/3/library/datetime.html#datetime.datetime.fromisoformat).
"""
from datetime import datetime
import sys
from_time = datetime.fromisoformat(sys.argv[1])
to_time = datetime.fromisoformat(sys.argv[2])
print(to_time - from_time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment