dateutils - Wrapper for Advanced Datetime Arithmetic
The `dateutils` library provides various utilities for working with date and datetime objects. It acts as a lightweight wrapper over the more comprehensive `python-dateutil` library, offering specialized features like advanced arithmetic operations, date range generation, and business day calculations. The last release was version 0.6.12 in October 2020.
Warnings
- gotcha Potential confusion with `python-dateutil`: This library, `dateutils` (without the hyphen in the package name, `pip install dateutils`), is a distinct, less actively maintained package. It acts as a wrapper around the much more widely used and actively developed `python-dateutil` library (installed via `pip install python-dateutil`, imported as `import dateutil`). Always ensure you are installing and importing the correct library for your needs.
- deprecated Project Maintenance Status: The `dateutils` library (jmcantrell/python-dateutils) has not seen a new release since October 2020. While functional, it relies on `python-dateutil` for its core logic, which is actively maintained. Users should be aware that direct support or new features for `dateutils` itself are unlikely.
Install
-
pip install dateutils
Imports
- DateUtils
from dateutils.api import DateUtils
Quickstart
from datetime import datetime, date
from dateutils.api import DateUtils
# Calculate the difference between two dates
date1 = date(2023, 1, 1)
date2 = date(2023, 1, 15)
diff_days = DateUtils.diff(date1, date2).days
print(f"Difference in days: {diff_days}")
# Generate a date range
start_date = date(2023, 3, 1)
end_date = date(2023, 3, 5)
dates_in_range = list(DateUtils.range(start_date, end_date))
print(f"Dates in range: {dates_in_range}")