Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
IT Security NachrichtenCalling viral AI actress Tilly Norwood? Agree to a face scan first(19.09.2026 um 13:38 Uhr)
Sicherheitslücken (CVE)SolarWinds Patches ARM Hard-Coded Key Flaw Enabling Unauthenticated RCE(19.09.2026 um 11:31 Uhr)
IT Security NachrichtenCalling viral AI actress Tilly Norwood? Agree to a face scan first(19.09.2026 um 13:38 Uhr)
Sicherheitslücken (CVE)SolarWinds Patches ARM Hard-Coded Key Flaw Enabling Unauthenticated RCE(19.09.2026 um 11:31 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

How to Calculate Business Days Between Two Dates in JavaScript

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:

https://greatuptools.com/business-days-calculator

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten How to Calculate Business Days Between Two Dates in JavaScript

Thematisch verwandte Begriffe: Calculate, Business, Days, Between · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-61591 | djust provides Phoenix LiveView-style reactive server-side rendering for…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Rechts: Artikel Ziehen Links: RSS
Hoch: nächster Artikel Runter: zurück / schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Rechts: Original Links: RSS-Ansicht
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick