Java Programs›Date & Time›Add Business Days to a Date

Add Business Days to a Date in Java

intermediate·  Date & Time  ·  Date & Time

Problem

Business days are the working days of the week, usually Monday to Friday, excluding weekends and public holidays.

Given an order date, find the date that is five business days later.

Input
Thursday 2026-03-12, 5 business days
Output
Thursday 2026-03-19

Java Program

Java
import java.time.DayOfWeek; import java.time.LocalDate; public class AddBusinessDays { static LocalDate addBusinessDays(LocalDate start, int days) { LocalDate d = start; int added = 0; while (added < days) { d = d.plusDays(1); DayOfWeek dow = d.getDayOfWeek(); if (dow != DayOfWeek.SATURDAY && dow != DayOfWeek.SUNDAY) added++; // skip weekends } return d; } public static void main(String[] args) { LocalDate orderDate = LocalDate.of(2026, 3, 12); // a Thursday System.out.println("Order placed: " + orderDate + " (" + orderDate.getDayOfWeek() + ")"); LocalDate due = addBusinessDays(orderDate, 5); System.out.println("Delivery by: " + due + " (" + due.getDayOfWeek() + ")"); } }

Output

Order placed: 2026-03-12 (THURSDAY) Delivery by: 2026-03-19 (THURSDAY)

Core Logic

Step forward one day at a time and count only the days that aren't Saturday or Sunday.

How It Works
  1. 1d starts at the order date and moves forward with plusDays(1).
  2. 2Each new day is counted only if its DayOfWeek isn't a weekend day.
  3. 3The loop stops after five business days have been counted.
  4. 4The result is printed with its weekday.
Friday 13, Monday 16, Tuesday 17, Wednesday 18 and Thursday 19 are the five business days.
💡

Key Point: Start counting from the day after the order date — counting the order date itself is a common off-by-one error.

Complexity
Time Complexity: O(n)Space Complexity: O(1)

Why: The loop visits roughly 7/5 × n calendar days to find n business days.

Key Concepts

plusDays()getDayOfWeek()DayOfWeek enum

Approach 2: Skipping Public Holidays

Java
import java.time.DayOfWeek; import java.time.LocalDate; import java.util.Set; public class AddBusinessDaysHolidays { public static void main(String[] args) { Set<LocalDate> holidays = Set.of(LocalDate.of(2026, 3, 16)); // a public holiday on Monday LocalDate d = LocalDate.of(2026, 3, 12); int added = 0; while (added < 5) { d = d.plusDays(1); boolean weekend = d.getDayOfWeek() == DayOfWeek.SATURDAY || d.getDayOfWeek() == DayOfWeek.SUNDAY; if (!weekend && !holidays.contains(d)) added++; } System.out.println("5 business days after 2026-03-12, skipping the holiday: " + d); } }

Output

5 business days after 2026-03-12, skipping the holiday: 2026-03-20

Core Logic

A set of holiday dates extends the same loop: a day counts only if it's a weekday and not in the set.

How It Works
  1. 1Set.of(...) holds the public holidays.
  2. 2Each day is checked against both the weekend rule and the holiday set.
  3. 3The loop otherwise works exactly like the weekend-only version.
Monday 16 March is a holiday, so the fifth business day moves from the 19th to the 20th.
💡

Key Point: Holiday lists vary by country and year, so real systems load them from configuration rather than code.

Complexity
Time Complexity: O(n)Space Complexity: O(h)

Why: Each day costs an O(1) set lookup, and the set holds h holidays.

Key Concepts

Set.of()holiday calendar

Interview Questions

How would you count business days between two dates?

Loop from the start to the end date and count weekdays, or compute whole weeks × 5 plus the weekdays in the remaining partial week.

What if an order is placed on a weekend?

Decide whether counting starts on the next Monday; the loop above already skips weekend days, so it works either way.

Learn the Concept

Related Programs