dev101.io

Date Difference Calculator

Calculate the difference between two dates in every unit.

Loading tool…

How to use Date Difference Calculator

  1. Pick a start date. Use the date picker, paste an ISO 8601 string like `2024-03-14T12:34:56Z`, or click a preset button (Now, Start of today, Start of year).
  2. Pick an end date the same way. A direction arrow between the two inputs shows whether you are moving forward or backward in time.
  3. Read the hero number for the whole-day count, the calendar chip for the year/month/day breakdown, and the unit grid for milliseconds, seconds, minutes, and hours.
  4. Scroll to the secondary grid for the age calculation, business-day count (Mon–Fri, no holidays), and signed millisecond delta.
  5. Click any Copy button to grab a single field for pasting into a ticket, a commit message, or a spreadsheet cell.
  6. Click Share to produce a URL that reloads both dates into the same tool on another device.

Date Difference Calculator

A single-screen date difference calculator that tells you everything you might need to know about the span between two timestamps: elapsed milliseconds, seconds, minutes, hours, and whole days; a calendar-aware breakdown of years, months, and days; a business-day count; an age figure; the weekday and ISO 8601 week number of each input; and the day count since the Unix epoch. The entire transform runs in your browser via native Date arithmetic, with zero dependencies and zero network calls, so pasting production timestamps never leaks them to a third-party server.

Why a dedicated date-diff tool

Every date library on the planet ships a "subtract one date from another" helper, yet nobody agrees on what the result should look like. JavaScript's Date.prototype - Date.prototype returns a number of milliseconds — useful for exact arithmetic, useless for "how many months between these?". Python's datetime subtraction returns a timedelta with only days and seconds because the authors decided that "months" is not a meaningful unit. Java's ChronoUnit.MONTHS.between does return months but rounds rather than breaking down into a (years, months, days) tuple. Excel's DATEDIF does the tuple but uses a 30-day month internally for one of its modes, so it silently disagrees with the other two modes on the same input.

This calculator takes the opposite stance: one input pair, every useful representation simultaneously. The hero number is the whole-day count because that is what people reach for first. The calendar chip is the borrow-based (years, months, days, hours, minutes, seconds) tuple that matches java.time.Period and dateutil.relativedelta. The unit grid exposes the raw elapsed figures for when you need them — diffMs / 86_400_000 for a chart bucket, diffSec for a Prometheus counter diff, diffHours for rate limiting. Age, business-day count, signed delta, direction arrow, ISO week, weekday, and epoch days are all derived in one pass and rendered without a single HTTP request.

What it does

  • Millisecond-accurate unit conversions — milliseconds, seconds, minutes, hours, and whole days between the two dates, all computed from a single UTC-anchored Date.getTime() diff so they are guaranteed internally consistent (absSeconds * 1000 === absMs, absDays * 86_400 === absSeconds to within the limits of JavaScript's leap-second-ignoring clock).
  • Calendar-aware breakdown — the span rendered as X years, Y months, Z days, H hours, M minutes, S seconds using borrow-based subtraction that matches java.time.Period. Borrowing from a month uses that specific month's real length (28, 29, 30, or 31 days), so Jan 31 → Mar 1 returns 1 month 1 day in a leap year and 1 month 1 day in a non-leap year — not 30 days rounded up.
  • Business-day count (Mon–Fri) — the number of weekdays strictly between the two dates. Fri → Mon returns 1 because Monday is the only weekday strictly after Friday and through Monday. No holiday calendar is applied; that is deliberate, because the "right" holiday list depends on the country and industry, and the Mon–Fri baseline is what every HR system starts from before layering regional holidays on top.
  • Age calculator — "You are X years, Y months, Z days old" when the end date is on or after the start date. Leap-year birthdays work correctly — someone born 2000-02-29 is 23y 11m 30d old on 2024-02-28 and 24y 0m 1d old on 2024-03-01.
  • Relative phrasing — a natural-language "in 5 days" or "2 years and 3 months ago" phrase that sticks to the top two calendar units so it reads the way a human would say it.
  • Per-input derived data — the weekday (Monday through Sunday in UTC), the ISO 8601 week number (week 1 contains the first Thursday of the year, so 2024-12-30 is week 1 of 2025), and the Unix epoch day count (1970-01-01 = day 0, 2024-01-01 = day 19,723).
  • Direction indicator — a →/← arrow between the two input cards so that a reversed interval is visually obvious. When the end is before the start the relative phrase switches to "X days ago" and the calendar breakdown stays positive with a negative badge on the result card.
  • URL-hash share — both dates are serialised into #s=… on Share, so you can paste a link into Slack or a ticket and the recipient sees the exact same diff.

What's not supported (yet)

  • Regional holiday calendars — the business-day count is strict Mon–Fri with no holiday exclusions. Pair it with your company's holiday list when you need bank-day precision.
  • Named-zone timezone conversion — if your two dates are in America/Los_Angeles and Asia/Tokyo the cleanest path is to first render each in ISO 8601 with offset form using the Timezone Converter, then paste those values here.
  • Cron or recurrence semantics — if you need "how many Mondays between these dates" or "how many times does this cron fire in the span", the Cron Expression Explainer is the purpose-built tool.
  • Arbitrary datetime formats — this tool accepts ISO 8601 (2024-03-14T12:34:56Z), YYYY-MM-DD, and the datetime-local format the browser picker emits (2024-03-14T12:34). For raw epoch integers, bounce through the Unix Timestamp Converter, which hands back an ISO string you can paste here.

How the calendar math actually works

The borrow-based algorithm used by the calendar breakdown is worth a paragraph because it is the same algorithm every serious date library converges on and it is easy to get wrong.

Given a start (y1, m1, d1, h1, mi1, s1) and an end (y2, m2, d2, h2, mi2, s2) with end ≥ start, the calculator subtracts pairwise: seconds from seconds, minutes from minutes, hours from hours, days from days, months from months, years from years. When a field goes negative it borrows one unit from the next-larger field. The borrow for days uses the previous month's actual length — if b.month is March, borrowing from it yields 29 (leap year) or 28 (non-leap) February days, not 30. That guarantees (y + dy, m + dm, d + dd) reconstructs the end date exactly when added to the start, which is the property you want for "how old is this record in human terms".

The alternative naive approach — dividing the millisecond delta by 86_400_000 * 365.25 — is useful for fuel-tank-level approximations but wrong for anything that faces a human. It will tell you that 2020-02-29 to 2024-02-29 is 3.99 years because a Julian year is 365.25 days and four calendar years average 365.25 days; it does not notice that the answer is, exactly and unsurprisingly, 4 years.

Why the transform runs entirely in the browser

Dates in production logs sit next to trace IDs, session cookies, user IDs, and customer identifiers. A server-side date-diff tool would receive every paste in its request logs, which means debugging a production timestamp could leak the rest of the log line to whoever runs the site. This tool implements every rule in hand-rolled JavaScript against the native Date API — no fetch, no XHR, no analytics on inputs, and no third-party scripts between your clipboard and the output grid. The Share button encodes both dates into the URL fragment (#s=…), which browsers never transmit to servers by design, so shared links preserve the same on-device privacy guarantee.

Related tools

  • ISO 8601 Parser — if either of your inputs is an ISO 8601 duration or interval rather than a plain datetime, the parser breaks them down explicitly and re-emits canonical forms you can then paste here.
  • Unix Timestamp Converter — the fastest way to turn a raw epoch integer into an ISO string and back, with every common rendering visible in a single grid.
  • Timezone Converter — when your two dates are in different IANA zones, render each one with its offset here first, then paste the offset-bearing strings into the date-diff calculator.

Frequently asked questions

How does this calculator count days between two dates?

The tool converts both inputs to UTC milliseconds and then divides the absolute difference by 86,400,000 (the number of milliseconds in a day). That means the "days" figure always matches wall-clock arithmetic regardless of whether a daylight-saving transition sits between the two dates. If you paste `2024-01-01` and `2024-01-31` you will see 30 whole days, which matches what every spreadsheet returns. For a calendar-aware answer that honours actual month lengths, read the calendar breakdown chip — it will tell you "1 month" instead of "30 days".

Why do I get a different answer than my spreadsheet for "X months" between two dates?

Most spreadsheets approximate a month as 30 days, so a span like 2022-01-15 to 2024-03-20 rounds to 26 whole months even though the calendar-correct answer is 2 years, 2 months, and 5 days. This tool uses a borrow-based algorithm that matches `java.time.Period` and Python's `dateutil.relativedelta` — it subtracts years first, then months, borrowing from the previous month's actual length when the day of month goes negative. The result is the shortest accurate year/month/day triplet that reconstructs the end date when added back to the start.

Does the business-day count include holidays?

No. The calculator counts Monday through Friday strictly between the two dates with zero holiday calendar applied. That keeps the answer deterministic and locale-independent — a Monday in Tokyo, New York, and Bangalore is still a Monday in this tool. If you need a holiday-aware count for a specific country, combine this number with your HR system's calendar or a regional holiday API; the Mon–Fri figure is usually the starting point every payroll and project-management formula begins with.

Does the result change if one of my dates is in a different timezone?

Only when you include an explicit offset. If you paste `2024-03-14T12:00:00+05:30` and `2024-03-14T06:30:00Z` the tool will parse both, convert each to UTC, and report a zero difference — they are the same instant expressed two ways. If you paste plain `YYYY-MM-DD` or a `datetime-local`-style string without an offset, the tool treats the input as UTC so the arithmetic is deterministic across machines. To compare times in two different zones, paste ISO 8601 strings with their offsets and the calculator does the rest.

How does the age calculator handle leap years?

Exactly the way a birthday works in real life. If you were born on 2000-02-29 and the end date is 2024-02-28 the tool reports 23 years, 11 months, 30 days — because 2024 has a February 29 that has not yet happened. On 2024-03-01 the age flips to 24 years, 0 months, 1 day. If the end date is before the start date the age field is blank because "age" is defined only for past-to-present spans. For pure future spans the relative phrase switches to "in X years, Y months" and the business-day and calendar counts continue to work in both directions.

What are "epoch days" and why are they useful?

Epoch days is the integer count of 24-hour periods since 1970-01-01 UTC, the Unix epoch. `1970-01-01` is day 0, `1970-01-02` is day 1, and `2024-01-01` is day 19,723. The figure is enormously useful when debugging serialized timestamps — databases such as PostgreSQL's `DATE` type, the JVM's `LocalDate.toEpochDay()`, and Cap'n Proto's `Date` all store dates as this integer. Pasting two dates and reading the epoch-days row is the fastest way to verify that your code's integer matches the human-readable string you expect.

Why does the ISO week of 2024-12-30 show "2025"?

The ISO 8601 week rule says week 1 of a year is the week containing the first Thursday. Because 2025-01-01 is a Wednesday, the Monday of ISO week 1 of 2025 is 2024-12-29 — so December 29 through 31 of 2024 belong to the 2025 week year. This is the convention used by PostgreSQL, Python's `%G-W%V-%u`, PHP's `o-W`, and every enterprise reporting system that exists. The calculator shows the "week year" next to the week number precisely so you notice this on December–early-January dates instead of getting burned by an off-by-one.

Related tools