Business Days
Calculate working days, exclude weekends, and optionally exclude holidays using numpy.busday or pandas.
Calculate working days, exclude weekends, and optionally exclude holidays using numpy.busday or pandas.
import numpy as np
from datetime import date, timedelta
start = np.datetime64("2024-06-10")
end = np.datetime64("2024-06-21")
bdays = np.busday_count(start, end) # working days between
in_5 = np.busday_offset(start, 5) # 5 business days from start
# Pure Python approach (weekdays only)
def add_business_days(dt, n):
while n > 0:
dt += timedelta(1)
if dt.weekday() < 5: n -= 1
return dt
For production finance/HR apps, use a holiday calendar — numpy.busdaycalendar accepts holiday arrays.