Open this example in the interactive library
Source code
from datetime import datetime
a = datetime.fromisoformat('2026-10-22T09:00:00')
b = datetime.fromisoformat('2026-10-22T10:30:00')
print((b-a).total_seconds())Sample output
5400.0

Calculate elapsed seconds. A self-contained example using the Python standard library.
Open this example in the interactive library
from datetime import datetime
a = datetime.fromisoformat('2026-10-22T09:00:00')
b = datetime.fromisoformat('2026-10-22T10:30:00')
print((b-a).total_seconds())5400.0