timedelta.total_seconds / days / seconds / microseconds
days, seconds and microseconds are the three normalized pieces — seconds is always 0–86399 and never includes the days. total_seconds() is the one number you usually want.
Common call
elapsed.total_seconds()
Returns
float — e.g. 90000.0 for 25 hours
Replaces
d.days * 86400 + d.seconds + d.microseconds / 1e6
Watch out
.seconds ignores the days part
td.total_seconds()
→ float
Demo
Live evaluation
Build a duration from hours and minutes, then read it back both ways.
Try:
Inputs
hoursinthours
minutesintminutes
Code
from datetime import timedelta d = timedelta(hours=0, minutes=90) (d.days, d.seconds, d.microseconds, d.total_seconds())
Result
(0, 5400, 0, 5400.0)
Watch the last value in "over a day": 25 hours apart, yet d.seconds is 3600 because the 24 hours went into d.days. With two different offsets the subtraction happens in UTC, so 09:00+02:00 and 09:00-04:00 are 6 hours apart.
Attributes
| Attribute | Type | Meaning |
|---|---|---|
| days | int | Whole days, -999999999..999999999. Carries the sign of the duration. |
| seconds | int | Seconds within the day, always 0..86399 — NOT the total. |
| microseconds | int | Microseconds within the second, always 0..999999. |
| total_seconds() | float | days * 86400 + seconds + microseconds / 10**6, computed exactly then rounded once to a float. |
Common patterns
Elapsed seconds between timestamps
Subtract, then total_seconds().
from datetime import datetime, UTC started = datetime.now(UTC) ... elapsed = (datetime.now(UTC) - started).total_seconds()
Whole hours and minutes
divmod the integer seconds.
hours, rest = divmod(int(d.total_seconds()), 3600) minutes = rest // 60
Duration in a unit, without floats
timedelta // timedelta is an int.
from datetime import timedelta full_hours = d // timedelta(hours=1)
Examples
1. The three fields
from datetime import timedelta
d = timedelta(days=2, hours=3, minutes=4, seconds=5, microseconds=6)
(d.days, d.seconds, d.microseconds)
Returns
(2, 11045, 6)2. total_seconds() adds them up
from datetime import timedelta
timedelta(days=2, hours=3, minutes=4, seconds=5, microseconds=6).total_seconds()
Returns
183845.0000063. Negative: only days is negative
from datetime import timedelta
d = timedelta(seconds=-1)
(d.days, d.seconds, d.total_seconds())
Returns
(-1, 86399, -1.0)4. Minutes as a float
from datetime import timedelta
timedelta(seconds=3661).total_seconds() / 60
Returns
61.0166666666666665. Whole hours with //
from datetime import timedelta
timedelta(minutes=90) // timedelta(hours=1)
Returns
16. Read-only
from datetime import timedelta
d = timedelta(days=1)
d.days = 2
Returns
AttributeError: readonly attribute7. Huge durations lose microseconds
from datetime import timedelta
timedelta.max.total_seconds()
Returns
86400000000000.0Pitfalls
1. .seconds for elapsed time
Works in testing with short intervals, then breaks the first time a run takes over a day.
.seconds
from datetime import datetime (datetime(2026, 9, 30, 10) - datetime(2026, 9, 29, 9)).seconds
3600
.total_seconds()
from datetime import datetime (datetime(2026, 9, 30, 10) - datetime(2026, 9, 29, 9)).total_seconds()
90000.0
2. Ignoring .days of a negative duration
A duration of -1 second has seconds=86399. Always look at .days too, or use total_seconds().
.seconds
from datetime import timedelta timedelta(seconds=-1).seconds
86399
.total_seconds()
from datetime import timedelta timedelta(seconds=-1).total_seconds()
-1.0
When to use
Use it
- Converting a duration to a number for storage, metrics or math
- .days when you need calendar days between two dates
Reach for something else
- .seconds for anything longer than a day
- Exact microsecond counts of very long durations → d // timedelta(microseconds=1) (an exact int)
Notes
CPython impl
total_seconds is delta_to_microseconds(self) / 10**6 — an exact integer divided once, so it is correctly rounded
Precision
A float has 53 bits: beyond about 270 years (2**33 seconds) it can no longer represent every microsecond, as timedelta.max shows
Attributes
days, seconds, microseconds are read-only; build a new timedelta instead
FAQ
Because it is only the seconds part below one day. timedelta(hours=26).seconds is 7200 — the other 24 hours are in .days. total_seconds() returns the full 93600.0.