Count business days

MediumDatetime Programs · 11 of 20

Write a Python program to count the working days (Monday to Friday) between two dates.

Advertisement
Input
2026-11-02 to 2026-11-30
Output
21

Approach

  1. Loop over each day and count weekdays.

Solution

Python
from datetime import date, timedelta def business_days(start, end):    count = 0    d = start    while d <= end:        if d.weekday() < 5:            count += 1        d += timedelta(days=1)    return count print(business_days(date(2026, 11, 2), date(2026, 11, 30)))
Output
21

Learn the concept

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

More datetime programs

← All 20 Datetime Programs

Leave a Comment