monthdelta
raw JSON → 0.9.1 verified Fri May 01 auth: no python
A Python library for date computations involving months, providing MonthDelta and MonthDate classes. Current version 0.9.1, last released in 2013. No active maintenance; may have compatibility issues with newer Python versions.
pip install monthdelta Common errors
error ImportError: No module named monthdelta ↓
cause monthdelta is not installed or Python environment issue.
fix
pip install monthdelta
error AttributeError: module 'datetime' has no attribute 'timedelta' ↓
cause Incorrect import of monthdelta's internal timedelta? Unlikely; this error may occur if user tries to use monthdelta while shadowing datetime.
fix
Ensure you import datetime module before monthdelta, or use from datetime import date, timedelta explicitly.
Warnings
gotcha MonthDelta behaves differently for dates with different number of days. Adding 1 month to Jan 31 gives Feb 28/29, not March 3. This may cause confusion if you expect strict 30-day increments. ↓
fix Understand that MonthDelta respects month boundaries, not day offsets. Use dateutil.relativedelta for more predictable behavior.
deprecated The library has not been updated since 2013. It may not work with Python 3.9+ due to removal of some deprecated datetime methods. ↓
fix Consider using dateutil.relativedelta as a drop-in replacement.
Imports
- MonthDelta wrong
from monthdelta import monthdeltacorrectfrom monthdelta import MonthDelta - MonthDate
from monthdelta import MonthDate
Quickstart
from monthdelta import MonthDelta, MonthDate
from datetime import date, datetime
# Add one month to a date
start = date(2020, 1, 31)
result = start + MonthDelta(1)
print(result) # 2020-02-29 (end-of-month aware)
# Difference in months between dates
d1 = date(2020, 1, 15)
d2 = date(2020, 3, 15)
md = MonthDelta(d2 - d1) # warning: may be inaccurate for uneven months
print(md.months) # 2
# Use MonthDate for month components
dt = MonthDate(2020, 2, 29)
print(dt) # 2020-02-29