Date Difference Calculator

Work out the difference between two dates as a calendar answer (1 year, 2 months, 3 days) and as totals of days, weeks, hours and business days. Months are counted on the calendar, so January 31 to February 28 is one month rather than 28 days.

Total days
Weeks and days
Business days (Mon to Fri)
Total hours
Total minutes
Total seconds

Add or subtract from a date

1 Date Difference Calculator example

Input

Start: 2024-01-31 09:00
End:   2025-03-01 17:30

Result

1 year, 1 month, 1 day, 8 hours, 30 minutes
Total days:     395 (plus 8h 30m)
Weeks and days: 56 weeks, 3 days
Business days:  283 (Mon to Fri)

2 How months are counted

Anchored on the start date

The calculator finds the largest number of whole months you can add to the start without passing the end, then counts the days left over. Months are always added to the original start date, never stepped one at a time, so the day of the month does not drift.

Short months clamp

January 31 plus one month is February 28 (29 in a leap year), the same rule PostgreSQL, Temporal and most date libraries use. So January 31 to February 28 is exactly one month, and January 31 to March 1 is one month and one day.

February 29

A leap-day start reaches its first anniversary on February 28 of the next year. Four years later it lands on February 29 again. Totals in days are unaffected, since those are a straight count.

Include end date

Off, Monday to Friday is 4 days, the way you count nights in a hotel. On, it is 5, the way you count days of annual leave or the days of a conference. Excel's NETWORKDAYS counts inclusively, so turn it on to match.

3 Time zones and daylight saving

Switch Clock to UTC when every day must be exactly 24 hours. By default both dates are read in your browser's local time zone. The calendar breakdown and the day counts use calendar days, so a day is a day even when the clocks change. However, the hour, minute and second totals are real elapsed time. A range that crosses a daylight saving change in local time is therefore an hour shorter or longer than days times 24, and a note under the totals says so.

Business days are Monday to Friday and nothing else. Public holidays differ by country, region and sometimes employer, so the calculator does not subtract them; take them off by hand. To convert a moment between two named zones, use the time zone converter instead.

How to use the Date Difference Calculator tool

  1. Pick the Start and End date and time. Both default to today at midnight. Set to now fills the end with the current time, and Example loads a month-end case.
  2. Set Clock to Local time or UTC, and tick Include end date if the last day should count as a full day.
  3. Read the breakdown in years, months, days, hours and minutes, and the totals: days, weeks and days, business days, hours, minutes and seconds. Swap flips the two dates.
  4. Use the Add or subtract section to move a date by a number of Days, Weeks, Months or Years.
  5. Click Copy Result to copy a plain-text summary, or Clear to reset everything to today.

How to calculate the difference between two dates in JavaScript, PHP and Python

JavaScript

// Calendar difference in whole years, months and days (dates only, no time zone)
function diffYMD(start, end) {           // "YYYY-MM-DD" strings, start <= end
  const [y1, m1, d1] = start.split("-").map(Number);
  const [y2, m2, d2] = end.split("-").map(Number);
  const dim = (y, m) => new Date(Date.UTC(y, m, 0)).getUTCDate(); // m is 1-based here
  const addMonths = (n) => {
    const t = y1 * 12 + (m1 - 1) + n, y = Math.floor(t / 12), m = (t % 12) + 1;
    return Date.UTC(y, m - 1, Math.min(d1, dim(y, m)));      // clamp Jan 31 -> Feb 28
  };
  const endMs = Date.UTC(y2, m2 - 1, d2);
  let months = (y2 - y1) * 12 + (m2 - m1);
  if (addMonths(months) > endMs) months--;
  const days = (endMs - addMonths(months)) / 86400000;
  return { years: Math.floor(months / 12), months: months % 12, days };
}

console.log(diffYMD("2024-01-31", "2025-03-01")); // { years: 1, months: 1, days: 1 }
console.log(diffYMD("2023-01-31", "2023-02-28")); // { years: 0, months: 1, days: 0 }

// Total days: use UTC so a DST change cannot make a day 23 hours long
const days = (a, b) => (Date.parse(b + "T00:00:00Z") - Date.parse(a + "T00:00:00Z")) / 86400000;
console.log(days("2026-03-01", "2026-04-01")); // 31

Once Temporal is available in your runtime, Temporal.PlainDate.from(start).until(end, { largestUnit: "year" }) does the same calendar math.

PHP

<?php
$start = new DateTimeImmutable("2024-01-31");
$end   = new DateTimeImmutable("2025-03-01");

$diff = $start->diff($end);
// 1y 0m 29d: PHP borrows days from the month before the end date,
// so a month-end start can come out differently from this tool (1y 1m 1d)
echo $diff->y, "y ", $diff->m, "m ", $diff->d, "d\n";
echo $diff->days, " days total\n";                    // 395
echo $diff->invert ? "negative\n" : "positive\n";

// Business days, Monday to Friday, end date excluded
$count = 0;
foreach (new DatePeriod($start, new DateInterval("P1D"), $end) as $day) {
    if ($day->format("N") < 6) $count++;
}
echo $count, " business days\n"; // 283

// Adding months overflows instead of clamping: Jan 31 + 1 month = Mar 2 (2024)
echo $start->modify("+1 month")->format("Y-m-d"), "\n";
echo $start->modify("last day of next month")->format("Y-m-d"), "\n"; // 2024-02-29

Python

from datetime import date, timedelta

start, end = date(2024, 1, 31), date(2025, 3, 1)

print((end - start).days)  # 395

# Business days, Monday to Friday, end date excluded
print(sum(1 for i in range((end - start).days)
          if (start + timedelta(days=i)).weekday() < 5))  # 283

# The standard library has no month arithmetic. python-dateutil does,
# and it clamps to the end of the month the same way this tool does:
#   from dateutil.relativedelta import relativedelta
#   relativedelta(end, start)             -> relativedelta(years=+1, months=+1, days=+1)
#   date(2024, 1, 31) + relativedelta(months=1)  -> date(2024, 2, 29)

Common errors and how to fix them

The result is off by one day
This is usually a counting convention. Monday to Friday is 4 days exclusive or 5 inclusive, so decide which you need and set Include end date to match. In JavaScript, new Date("2026-09-30") is midnight UTC while new Date("2026-09-30T00:00") is midnight local time, which can also shift a day.
A day comes out as 23 or 25 hours
The range crosses a daylight saving change in local time. Count calendar days (compare dates as UTC midnights) instead of dividing milliseconds by 86,400,000, or do the whole calculation in UTC.
January 31 plus one month gives March 2 or 3
JavaScript setMonth() and PHP modify("+1 month") overflow into the next month instead of clamping. Clamp the day to the length of the target month, or in PHP use modify("last day of next month") when that is what you mean.
PHP diff() disagrees with this calculator on months and days
DateTime::diff() borrows days from the month before the end date, so 2024-01-31 to 2025-03-01 comes out as 1 year, 0 months, 29 days instead of 1 year, 1 month, 1 day. Both answers are defensible, and the total in days (395) is the same.
Business days do not match the payroll system
Only Saturdays and Sundays are excluded here. Subtract public holidays for your region, and check whether the other system counts the start and end dates inclusively.

Good to know

The calculator works from each date's year, month and day fields rather than from millisecond timestamps, so the breakdown never picks up a stray hour from a clock change. Only the hour, minute and second totals use real elapsed time, from your browser's time zone data or from UTC.

Specifications and references

This tool follows the specifications below. Read them when you need the exact normative wording, for example to settle an edge case between two implementations.

Frequently Asked Questions

How many days are there between two dates?

Enter the Start and End dates and read Total days. The end date is not counted by default, so Monday to Friday is 4 days; tick Include end date to count it and get 5.

How are months counted when the start is the 31st?

Months are added to the start date and clamped to the end of shorter months, so January 31 plus one month is February 28, or February 29 in a leap year. That makes January 31 to February 28 exactly one month.

Does it count business days?

Yes, Monday to Friday between the two dates. Public holidays are not subtracted, because they differ by country and region.

Why are the total hours not equal to days times 24?

In local time, a range that crosses a daylight saving change contains a 23-hour or 25-hour day. Days are counted as calendar days and hours as real elapsed time, and a note under the totals points out the difference. Switch Clock to UTC for 24-hour days.

Can I add or subtract days from a date?

Yes. The Add or subtract section takes a date, an amount and a unit (Days, Weeks, Months or Years) and shows the resulting date with its weekday. Month and year steps clamp to the last day of the month when needed.

Other date tools

Turn a date into epoch seconds with the Unix timestamp converter, reformat it with the date converter, or move a meeting across zones with the time zone converter.

More Date & Time Tools

Browse all date & time tools

Copied to clipboard!