Python Practice › Datetime Programs › Program 4
Add and subtract days
Write a Python program to find the dates 30 days after and 7 days before a date.
Output
2026-12-02 2026-10-26
Approach
- Add or subtract a
timedelta.
Solution
from datetime import date, timedelta d = date(2026, 11, 2)print(d + timedelta(days=30), d - timedelta(days=7))Output
2026-12-02 2026-10-26
Learn the concept
New to this topic? Read the lesson, then come back.