When working with dates in JavaScript, calculating the difference between two dates is easy if you only need calendar days.
But in real business use cases, we often need to calculate business days, also called working days.
Business days usually exclude Saturdays and Sundays. In some cases, public holidays also need to be excluded.
I created a free online Business Days Calculator for checking this quickly:
https://greatuptools.com/business-days-calculator
What are business days?
Business days usually mean Monday to Friday.
Saturday and Sunday are normally excluded because they are weekends.
For example:
Business days: Monday, Tuesday, Wednesday, Thursday, Friday
Weekend days: Saturday, Sunday
Basic JavaScript date difference
If you only want the number of calendar days between two dates, you can subtract two dates in JavaScript:
Code example:
const startDate = new Date("2026-01-01");
const endDate = new Date("2026-12-31");
const millisecondsPerDay = 1000 * 60 * 60 * 24;
const differenceInDays = Math.floor((endDate - startDate) / millisecondsPerDay);
console.log(differenceInDays);
This counts calendar days, not business days.
Calculate business days in JavaScript
To calculate business days, we can loop through each date and skip Saturday and Sunday.
Code example:
function getBusinessDays(startDate, endDate) {
const start = new Date(startDate);
const end = new Date(endDate);
if (end < start) {
return 0;
}
let count = 0;
const current = new Date(start);
while (current <= end) {
const day = current.getDay();
// 0 = Sunday, 6 = Saturday
if (day !== 0 && day !== 6) {
count++;
}
current.setDate(current.getDate() + 1);
}
return count;
}
console.log(getBusinessDays("2026-01-01", "2026-12-31"));
How the logic works
JavaScript's getDay() method returns a number from 0 to 6.
0 = Sunday
1 = Monday
2 = Tuesday
3 = Wednesday
4 = Thursday
5 = Friday
6 = Saturday
So the logic is simple:
Code example:
if (day !== 0 && day !== 6) {
count++;
}
This means we count only Monday to Friday.
Inclusive vs exclusive date counting
The above example includes both the start date and the end date.
For example, Monday to Friday gives:
Monday = 1
Tuesday = 2
Wednesday = 3
Thursday = 4
Friday = 5
So the result is 5 business days.
In some cases, you may want to exclude the start date. In that case, you can start counting from the next day.
Business days with public holidays
In real applications, weekends are not the only thing to exclude.
Sometimes you also need to exclude public holidays.
For example:
Code example:
const holidays = [
"2026-01-26",
"2026-08-15",
"2026-10-02"
];
Then you can update the function:
Code example:
function getBusinessDaysExcludingHolidays(startDate, endDate, holidays = []) {
const start = new Date(startDate);
const end = new Date(endDate);
if (end < start) {
return 0;
}
const holidaySet = new Set(holidays);
let count = 0;
const current = new Date(start);
while (current <= end) {
const day = current.getDay();
const dateString = current.toISOString().split("T")[0];
const isWeekend = day === 0 || day === 6;
const isHoliday = holidaySet.has(dateString);
if (!isWeekend && !isHoliday) {
count++;
}
current.setDate(current.getDate() + 1);
}
return count;
}
console.log(
getBusinessDaysExcludingHolidays("2026-01-01", "2026-12-31", [
"2026-01-26",
"2026-08-15",
"2026-10-02"
])
);
Common use cases
Business day calculation is useful for:
- Project deadlines
- Invoice due dates
- Delivery estimates
- SLA tracking
- HR leave calculation
- Payroll
- Banking and finance timelines
Try it online
If you do not want to manually calculate business days every time, I built a free online calculator here:
https://greatuptools.com/business-days-calculator
It supports date ranges, weekends, countries, holidays, and result sharing.
Final thoughts
Calculating calendar days is simple in JavaScript, but business day calculation needs extra logic.
The basic rule is:
- Count Monday to Friday
- Skip Saturday and Sunday
- Optionally exclude public holidays
For quick manual checking, you can use this free Business Days Calculator:

Top comments (0)