Workdays Date Utility

1.5 · active · verified Fri Apr 17

The `workdays` library provides utility functions to calculate working days between two dates, extending Python's standard `datetime` module. The current version is 1.5, with an infrequent release cadence focused on maintenance and minor enhancements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `networkdays` function to calculate the number of working days between two dates, accounting for a list of specified holidays. All date inputs must be `datetime.date` objects.

from datetime import date
from workdays import networkdays

# Define start and end dates as datetime.date objects
start_date = date(2023, 1, 1)
end_date = date(2023, 1, 31)

# Define a list of holidays, also as datetime.date objects
holidays = [
    date(2023, 1, 1), # New Year's Day
    date(2023, 1, 16) # MLK Day
]

# Calculate network days (excluding weekends and specified holidays)
num_workdays = networkdays(start_date, end_date, holidays)
print(f"Number of network days between {start_date} and {end_date}: {num_workdays}")

# You can also specify custom weekend days (1=Monday, 7=Sunday, ISO weekday)
# For example, to make Friday, Saturday, Sunday weekends (5, 6, 7):
# num_workdays_custom_weekend = networkdays(start_date, end_date, holidays, weekend_days=[5, 6, 7])
# print(f"Network days with custom weekends (Fri, Sat, Sun off): {num_workdays_custom_weekend}")

view raw JSON →