BizDay

How to Calculate Business Days in Python

Skip weekends. Skip holidays. Get the right date every time.

The Problem

Calculating business days sounds simple until you actually try to do it. Need to figure out a delivery date that is 10 business days from now? Or count the working days between two dates for an invoice? If you have ever written date logic for a production system, you know that weekends are only the beginning of the problem.

Public holidays vary by country, by state, and sometimes by city. They change year to year. Some are based on lunar calendars. Getting this right in Python requires more than datetime and a weekend check.

The Naive Approach: Skipping Weekends

The most common starting point is a simple loop that skips Saturdays and Sundays. Here is what that looks like:

skip_weekends.py
from datetime import date, timedelta

def add_business_days(start: date, days: int) -> date:
    current = start
    added = 0
    while added < days:
        current += timedelta(days=1)
        if current.weekday() < 5:  # Mon-Fri
            added += 1
    return current

# 10 business days from March 5, 2026
result = add_business_days(date(2026, 3, 5), 10)
print(result)  # 2026-03-19

This works for the simplest case. But it has a glaring problem: it treats every Monday through Friday as a working day. In the real world, that is not true.

Why Holidays Make It Hard

Consider March 2026 in the United States. The naive approach above says there are 22 business days. But if Good Friday is observed by your organization, the real count is 21. In Germany, the count may be different because of regional holidays that only apply in certain states.

Hardcoding holidays is a common next step, but it creates a maintenance burden that compounds over time:

A Better Approach: Use an API

Instead of maintaining your own holiday data, you can offload this to a service that keeps holiday calendars up to date for 30+ countries. The BizDay API is built specifically for this. Let us look at how to use it with Python.

Check if a Date Is a Business Day

check_business_day.py
import requests

API_KEY = "wday_your_api_key"
BASE_URL = "https://api.bizday.dev"

def is_business_day(date_str: str, country: str = "US") -> bool:
    resp = requests.get(
        f"{BASE_URL}/v1/check",
        params={"date": date_str, "country": country},
        headers={"Authorization": f"Bearer {API_KEY}"},
    )
    data = resp.json()
    return data["data"]["is_workday"]

print(is_business_day("2026-12-25", "US"))
# False — Christmas Day

Add Business Days to a Date

This is the API equivalent of the naive loop we wrote earlier, except it accounts for all public holidays in the given country:

add_business_days_api.py
def add_business_days(date_str: str, days: int, country: str = "US") -> str:
    resp = requests.get(
        f"{BASE_URL}/v1/add",
        params={"date": date_str, "days": days, "country": country},
        headers={"Authorization": f"Bearer {API_KEY}"},
    )
    data = resp.json()
    return data["data"]["result_date"]

# 10 business days from March 5, 2026 in Germany
result = add_business_days("2026-03-05", 10, "DE")
print(result)  # Correctly skips German public holidays

Count Business Days Between Two Dates

Perfect for billing periods, SLA calculations, or project timelines:

count_between.py
def business_days_between(start: str, end: str, country: str = "US") -> int:
    resp = requests.get(
        f"{BASE_URL}/v1/between",
        params={"start": start, "end": end, "country": country},
        headers={"Authorization": f"Bearer {API_KEY}"},
    )
    data = resp.json()
    return data["data"]["workdays"]

# Working days in Q1 2026 for the UK
count = business_days_between("2026-01-01", "2026-03-31", "GB")
print(f"Q1 2026 has {count} working days in the UK")

When to Use an API vs. a Library

Python libraries like numpy.busday_count and pandas.bdate_range handle weekday math well, but they do not include holiday data out of the box. You can pass a custom holiday list, but then you are back to maintaining that list yourself.

An API-based approach is the right choice when:

Getting Started

The BizDay API has a free tier with 10,000 requests per month and no credit card required. You can get an API key in seconds and start making requests immediately. Check the full documentation for all available endpoints and parameters.