{"id":10357,"library":"workdays","title":"Workdays Date Utility","description":"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.","status":"active","version":"1.5","language":"en","source_language":"en","source_url":"http://github.com/ogt/workdays","tags":["date","datetime","workday","holiday","utility","business-days"],"install":[{"cmd":"pip install workdays","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"networkdays","correct":"from workdays import networkdays"}],"quickstart":{"code":"from datetime import date\nfrom workdays import networkdays\n\n# Define start and end dates as datetime.date objects\nstart_date = date(2023, 1, 1)\nend_date = date(2023, 1, 31)\n\n# Define a list of holidays, also as datetime.date objects\nholidays = [\n    date(2023, 1, 1), # New Year's Day\n    date(2023, 1, 16) # MLK Day\n]\n\n# Calculate network days (excluding weekends and specified holidays)\nnum_workdays = networkdays(start_date, end_date, holidays)\nprint(f\"Number of network days between {start_date} and {end_date}: {num_workdays}\")\n\n# You can also specify custom weekend days (1=Monday, 7=Sunday, ISO weekday)\n# For example, to make Friday, Saturday, Sunday weekends (5, 6, 7):\n# num_workdays_custom_weekend = networkdays(start_date, end_date, holidays, weekend_days=[5, 6, 7])\n# print(f\"Network days with custom weekends (Fri, Sat, Sun off): {num_workdays_custom_weekend}\")","lang":"python","description":"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."},"warnings":[{"fix":"Review existing `networkdays` calls and consider explicitly setting the `weekend_days` parameter, e.g., `weekend_days=[6, 7]` for Saturday and Sunday.","message":"Version 1.5 (released Feb 2023) introduced \"flexibility of weekends\". While not explicitly detailed as breaking, if your code relied on specific implicit default weekend behavior prior to 1.5, it's safest to explicitly define the `weekend_days` argument in your `networkdays` calls to maintain consistent behavior.","severity":"breaking","affected_versions":">=1.5"},{"fix":"Ensure `holidays` is always an iterable of `datetime.date` objects. Convert strings using `datetime.strptime().date()` and `datetime.datetime` objects using `.date()`.","message":"The `holidays` argument for `networkdays` expects an iterable (e.g., a list or tuple) containing `datetime.date` objects. Passing strings, `datetime.datetime` objects, or a single `datetime.date` object directly (without being in a list) will lead to `TypeError` or incorrect calculations.","severity":"gotcha","affected_versions":"All"},{"fix":"Upgrade to the latest version of `workdays` using `pip install --upgrade workdays`.","message":"Versions of `workdays` prior to `1.2` had known compatibility issues with Python 3. If you are running an older version on Python 3 and encounter unexpected errors, an upgrade is necessary.","severity":"gotcha","affected_versions":"<1.2"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Convert date strings to `datetime.date` objects using `datetime.strptime('YYYY-MM-DD', '%Y-%m-%d').date()` or `date(year, month, day)`.","cause":"You are passing a date string directly to `networkdays` or within the `holidays` list instead of a `datetime.date` object.","error":"TypeError: 'str' object cannot be interpreted as a date"},{"fix":"Wrap single holiday dates in a list: `holidays=[date(2023, 1, 1)]`.","cause":"You are passing a single `datetime.date` or `datetime.datetime` object directly to the `holidays` parameter, which expects an iterable (like a list).","error":"TypeError: 'datetime.datetime' object is not iterable"},{"fix":"Ensure all date inputs are `datetime.date` objects. If you have a `datetime.datetime` object, convert it using `.date()`: `my_datetime_obj.date()`.","cause":"You are passing `datetime.datetime` objects where `datetime.date` objects are expected (e.g., for `start_date`, `end_date`, or elements in `holidays`).","error":"AttributeError: 'datetime.datetime' object has no attribute 'weekday'"}]}