All dates in a range

EasyDatetime Programs · 13 of 20

Write a Python program to list every date in a week.

Advertisement
Output
2026-11-02 Mon
2026-11-03 Tue
2026-11-04 Wed
2026-11-05 Thu
2026-11-06 Fri
2026-11-07 Sat
2026-11-08 Sun

Approach

  1. Add 0 to 6 days to the start.

Solution

Python
from datetime import date, timedelta start = date(2026, 11, 2)for i in range(7):    d = start + timedelta(days=i)    print(d, d.strftime("%a"))
Output
2026-11-02 Mon
2026-11-03 Tue
2026-11-04 Wed
2026-11-05 Thu
2026-11-06 Fri
2026-11-07 Sat
2026-11-08 Sun

Learn the concept

New to this topic? Read the lesson, then come back.

More datetime programs

← All 20 Datetime Programs

Leave a Comment