Add and subtract days

EasyDatetime Programs · 4 of 20

Write a Python program to find the dates 30 days after and 7 days before a date.

Advertisement
Output
2026-12-02 2026-10-26

Approach

  1. Add or subtract a timedelta.

Solution

Python
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.

More datetime programs

← All 20 Datetime Programs

Leave a Comment