User Rating 0.0
Total Usage 0 times
Category Time
Is this tool helpful?

Your feedback helps us improve.

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.

duration calculator time between dates date difference hours between times working days calculator elapsed time time span

Formulas

The total millisecond difference between two timestamps is computed as:

Δms = tend tstart

Flat-unit conversions derive from this delta:

totalSeconds = Δms1000
totalMinutes = Δms60000
totalHours = Δms3600000
totalDays = Δms86400000
totalWeeks = totalDays7

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:

isLeap(y) = (y mod 4 = 0) (y mod 100 0 y mod 400 = 0)

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

MonthDays (Common Year)Days (Leap Year)Cumulative Days (Common)Cumulative Days (Leap)
January31313131
February28295960
March31319091
April3030120121
May3131151152
June3030181182
July3131212213
August3131243244
September3030273274
October3131304305
November3030334335
December3131365366

Frequently Asked Questions

The algorithm walks through each month boundary individually. When computing remaining days, it uses the actual number of days in each specific month (28, 29, 30, or 31). For example, a span from January 31 to March 1 correctly reports 1 month and 1 day in a leap year (29 days in February) or 1 month and 1 day in a common year (28 days in February), because February is traversed as a full month regardless of its length.
No. Working days are calculated by excluding only Saturdays and Sundays. Public holidays vary by jurisdiction and year, making a universal list impractical. For payroll or legal compliance, subtract your applicable public holidays from the working days total manually. A typical year has approximately 10-15 public holidays in most countries.
Because months have variable lengths (28-31 days) and years can be 365 or 366 days. The compound breakdown (Y/M/D) is calendar-aware and walks actual month boundaries, while total days is a simple division of the millisecond delta by 86,400,000. These two representations measure the same span differently. The compound form is useful for human communication; the flat total is useful for arithmetic.
The Gregorian leap year rule is applied: a year is a leap year if it is divisible by 4, except for century years, which must also be divisible by 400. Thus 2000 was a leap year (divisible by 400), 1900 was not (divisible by 100 but not 400), and 2024 is a leap year (divisible by 4, not a century year). This affects February's day count and therefore any span crossing February.
No. All calculations assume uniform 24-hour days. A DST transition can cause a calendar day to be 23 or 25 hours long. For spans crossing DST boundaries, the hour/minute/second components may differ from wall-clock elapsed time by ±1 hour. For sub-day precision in DST-aware contexts, use a timezone-aware library or IANA timezone database.
The tool accepts dates from January 1, 0001 to December 31, 9999, constrained by the HTML date input and JavaScript Date object range. In practice, JavaScript Date reliably handles dates from approximately April 20, 271,821 BCE to September 13, 275,760 CE, but this tool clamps to the 0001-9999 CE range for practical use.