Clock Duration Calculator
Calculate exact duration between two dates and times. Get years, months, days, hours, minutes, seconds, working days, and total unit breakdowns.
About
Miscounting elapsed time costs real money in payroll, contract billing, and project management. A naive subtraction of two dates ignores variable month lengths (28, 29, 30, or 31 days), leap years, and the distinction between calendar days and working days. This calculator performs calendar-aware arithmetic: it walks month boundaries precisely, accounts for February anomalies in leap years, and separately tallies weekdays (excluding Saturday and Sunday) for business contexts. Results are expressed both as a compound breakdown (Y years, M months, D days, h hours, m minutes, s seconds) and as flat totals in each unit.
Limitations: this tool uses the Gregorian calendar only and does not account for public holidays or custom non-working days when computing business days. Daylight Saving Time transitions are not modeled. All calculations assume uniform 24-hour days. For payroll or legal contexts, verify results against jurisdiction-specific holiday schedules.
Formulas
The total millisecond difference between two timestamps is computed as:
Flat-unit conversions derive from this delta:
The compound breakdown (Y years, M months, D days) uses calendar-aware iteration. Starting from tstart, the algorithm increments full years while the resulting date does not exceed tend, then full months, then counts remaining days. This correctly handles months of varying length and leap-year February.
Leap year detection follows the Gregorian rule:
Working days are computed by iterating each calendar day in the range and excluding those where the day-of-week is Saturday (6) or Sunday (0).
Where tstart = start datetime timestamp in ms, tend = end datetime timestamp in ms, Δms = absolute millisecond difference, Y = full calendar years, M = remaining full months, D = remaining days, y = year number for leap test.
Reference Data
| Month | Days (Common Year) | Days (Leap Year) | Cumulative Days (Common) | Cumulative Days (Leap) |
|---|---|---|---|---|
| January | 31 | 31 | 31 | 31 |
| February | 28 | 29 | 59 | 60 |
| March | 31 | 31 | 90 | 91 |
| April | 30 | 30 | 120 | 121 |
| May | 31 | 31 | 151 | 152 |
| June | 30 | 30 | 181 | 182 |
| July | 31 | 31 | 212 | 213 |
| August | 31 | 31 | 243 | 244 |
| September | 30 | 30 | 273 | 274 |
| October | 31 | 31 | 304 | 305 |
| November | 30 | 30 | 334 | 335 |
| December | 31 | 31 | 365 | 366 |