induwara.lk
induwara.lkDate · Time

Date Difference Calculator — Days, Weeks, Months, Years

Find the exact gap between two dates broken down into years, months, days, weeks, hours, and minutes — plus a working-days count that strips out weekends. Leap-year accurate, DST-aware, runs entirely in your browser.

By Induwara AshinsanaUpdated May 11, 2026
Days between two dates
Cross-checked · 2 algorithms

Friday, July 3, 2026

Sunday, August 2, 2026

Quick presets
Calendar difference
0
years
0
months
30
days

FridaySunday · 30 days total · ISO 8601: P30D

Total span

Months
0
Weeks
4
+ 2 days
Days
30
Hours
720
Minutes
43,200
Seconds
2,592,000
Business days only (Mon–Fri)
Working days
21
Weekend days
9
5 Sat · 4 Sun
Total span
30
Work 21 + weekend 9

Weekends only — public holidays are not subtracted. For a Sri Lanka-specific count that excludes gazetted public, bank, and mercantile holidays, use the Sri Lanka Working Days Calculator.

Days and Y/M/D cross-checked against an independent algorithm and verified by round-trip addition. Methodology last verified 2026-05-11. All arithmetic runs in your browser — nothing is uploaded.

How it works

The calculator answers two related questions: how many days separate two dates, and how that gap reads as a calendar duration like "2 years, 3 months, 5 days". Both use the half-open interval [start, end) — the start date is day zero and the end date itself is not counted, so 1 Jan to 2 Jan is exactly one day. This is the same convention used by the date-fns library and by mainstream date calculators such as timeanddate.com and calculator.net.

For the day count, the algorithm converts each input to a UTC-midnight day number — the number of whole days since 1 Jan 1970 UTC — and subtracts. Using UTC sidesteps daylight-saving transitions, so a day in a region that shifts the clock still counts as exactly one day. The same day numbers feed the working-days count: each whole week in the interval contributes five weekdays, and the remaining 0–6 days are checked one by one against their day-of-week to decide whether each is a weekend or a weekday.

For the calendar-aware breakdown, the algorithm follows the date-fns differenceInMonths anniversary rule. Given start S and end E:

  1. Compute raw month gap: M = (E.year − S.year) × 12 + (E.month − S.month).
  2. If E.day < S.day (the anniversary hasn't arrived in the final month), subtract one from M.
  3. Split into years and months: years = ⌊M / 12⌋, months = M mod 12.
  4. Build an anchor date S + M months, clamping the day-of-month to the last day of the resulting month (so adding one month to 31 Jan gives 28 Feb in a non-leap year, not 3 Mar).
  5. Count days from the anchor to E. The breakdown reconciles exactly: S + Y years + M months + D days = E.

To guard against single-algorithm bugs, the total-days figure is cross-checked against a second implementation that counts UTC midnights independently, and the Y/M/D breakdown is verified by adding it back to the start date — both checks must pass before the "cross-checked" badge appears in the calculator header.

For leap-year inputs the Gregorian rule applies in full — years divisible by 4 except centuries unless divisible by 400. That makes 2000 a leap year but 1900 not, and 2024 leap but 2025 not. The Sri Lanka Registrar General's practice of rolling Feb 29 anniversaries to Feb 28 in non-leap years is exactly what the anchor-clamp step produces here.

Worked examples

Mon 5 Jan 2026 → Fri 9 Jan 2026 (work week)

  1. Day count: 9 − 5 = 4 days
  2. Y/M/D: M = 0 × 12 + 0 = 0; 9 ≥ 5, no anniversary subtraction → years = 0, months = 0
  3. Anchor: 5 Jan + 0 months = 5 Jan; days from anchor to 9 Jan = 4
  4. Result: 0y 0m 4d, total 4 days
  5. Working days [Mon, Fri): Mon, Tue, Wed, Thu = 4 weekdays, 0 weekends

Sat 29 Feb 2024 → Sat 1 Mar 2025 (leap day → next year)

  1. Day count: from 2024-02-29 UTC midnight to 2025-03-01 UTC midnight = 366 days
  2. Y/M/D: M = 1 × 12 + (2 − 1) = 13; end.day (1) < start.day (29) → M = 12
  3. Years = 1, months = 0
  4. Anchor: 29 Feb 2024 + 12 months = clamp to 28 Feb 2025 (2025 not a leap year)
  5. Days from 28 Feb 2025 to 1 Mar 2025 = 1
  6. Result: 1y 0m 1d
  7. Verify: 29 Feb 2024 + 1 year = 28 Feb 2025 → + 1 day = 1 Mar 2025 ✓

Sat 31 Jan 2026 → Sun 1 Mar 2026 (month-end clamp)

  1. Day count: 31 + 28 + 1 = day-of-year 60 minus day-of-year 31 = 29 days
  2. Y/M/D: M = 0 × 12 + 2 = 2; end.day (1) < start.day (31) → M = 1
  3. Years = 0, months = 1
  4. Anchor: 31 Jan + 1 month = clamp to 28 Feb 2026 (2026 not a leap year)
  5. Days from 28 Feb to 1 Mar = 1
  6. Result: 0y 1m 1d, total 29 days
  7. Working days: 31 Jan is a Saturday so the start sits on a weekend. 4 whole weeks contribute 20 weekdays, the 1-day remainder is another Saturday → 20 weekdays, 9 weekend days in [start, end)

Frequently asked questions

Sources & references

Algorithm and worked examples last cross-checked on 2026-05-11. The calendar arithmetic doesn't change, so this page is reviewed annually rather than on a fixed schedule.

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want to suggest an improvement?

Email me at [email protected] — most fixes ship within 24 hours.