datedelta

raw JSON →
1.4 verified Fri May 01 auth: no python

Provides a DateDelta class for arithmetic between dates, similar to datetime.timedelta but for date objects. Current version 1.4, release cadence is low (last release 2019).

pip install datedelta
error TypeError: unsupported operand type(s) for +: 'datetime.datetime' and 'DateDelta'
cause DateDelta can only be added to date objects, not datetime objects.
fix
Use .date() on the datetime before adding: some_datetime.date() + DateDelta(...)
error AttributeError: module 'datedelta' has no attribute 'DateDelta'
cause Attempting to import DateDelta incorrectly (e.g., import datedelta; datedelta.DateDelta) whereas the correct import is 'from datedelta import DateDelta'.
fix
Use 'from datedelta import DateDelta'
error TypeError: unsupported operand type(s) for -: 'DateDelta' and 'DateDelta'
cause DateDelta does not support subtraction between two DateDelta objects.
fix
Use DateDelta(years=..., months=..., days=...) to construct the delta you need.
gotcha DateDelta cannot be added to datetime objects, only date objects. Attempting to add to datetime causes a TypeError.
fix Convert datetime to date first: some_datetime.date() + datedelta
gotcha Adding a DateDelta with months to a date near month end can produce unexpected results (e.g., Jan 31 + 1 month = Feb 28/29). No month overflow to next month.
fix Be aware of month-end clamping behavior; it's by design.
gotcha DateDelta only supports years, months, weeks, days. No support for hours, minutes, seconds, or microseconds.
fix Use datetime.timedelta for sub-day precision.

Add a DateDelta to a date to get another date.

from datetime import date
from datedelta import DateDelta, DAYS, MONTHS, YEARS

today = date.today()
delta = DateDelta(years=1, months=2, days=10)
new_date = today + delta
print(new_date)

# Or using constants:
new_date2 = today + 1*YEARS + 2*MONTHS + 10*DAYS
print(new_date2)