Eskillsfy

Home / Blog / Calculators

Calculators · 23 Nov 2026

Date Difference Calculator: how it works and how to build one

Days between two dates, and add or subtract days. This guide explains what happens behind the button and shows the code, so you can build your own.

What it does

Count the days, weeks and months between two dates, with an option to count only working days (Monday to Friday). Or add or subtract days, weeks or months from a date to find a deadline.

When to use it

  • Notice periods and deadlines
  • Project planning
  • Counting leave days

How to use it

  1. Pick Difference or Add/subtract.
  2. Choose the dates or amount.
  3. Read the result.

Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/date-calculator

How it works

Days between two dates is the difference in milliseconds divided by 86,400,000, using UTC so daylight saving doesn’t skew it. Working days loop over each day and skip Saturdays (6) and Sundays (0).

Adding months uses setMonth, which rolls over correctly (31 January + 1 month becomes 3 March in JavaScript, so production code often clamps to the last day of the month).

Build it yourself

Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any TypeScript or JavaScript project.

dates.ts (ts)

const utc = (d: Date) => Date.UTC(d.getFullYear(), d.getMonth(), d.getDate());

export const daysBetween = (a: Date, b: Date) => Math.round((utc(b) - utc(a)) / 864e5);

export function workingDays(a: Date, b: Date) {
  let n = 0;
  for (const d = new Date(a); d < b; d.setDate(d.getDate() + 1)) if (d.getDay() % 6 !== 0) n++;
  return n;
}

export const addDays = (d: Date, n: number) => { const x = new Date(d); x.setDate(x.getDate() + n); return x; };

Make it production-ready

  • Add a list of public holidays to skip.
  • Clamp month additions to the end of the month.

Questions

Is the end date included?

There’s a checkbox for that, because contracts and leave often count both days.

Try the Date Difference Calculator

Free, runs in your browser, nothing is uploaded.

Open it
Keep reading

More in Calculators

All posts