Python Practice › Datetime Programs › Program 18
Next Monday
Write a Python program to find the date of the next Monday after a given date.
Output
2026-11-02 -> 2026-11-09 2026-11-05 -> 2026-11-09
Approach
- Days to add = (7 – weekday) % 7, or a full 7 days if the date is already a Monday.
Solution
from datetime import date, timedelta def next_monday(d): return d + timedelta(days=(7 - d.weekday()) % 7 or 7) for d in [date(2026, 11, 2), date(2026, 11, 5)]: print(d, "->", next_monday(d))Output
2026-11-02 -> 2026-11-09 2026-11-05 -> 2026-11-09
Line by line
Line 4
For a Monday the formula gives 0, so or 7 moves to the following Monday.
Learn the concept
New to this topic? Read the lesson, then come back.