Editor

Python Program to Find the Day of the Week for a Date

Beginner · Dates and times

This program finds the day of the week, such as Monday or Friday, for any date. Python's date objects know their own weekday, so the program asks for it as a number and as a name, and checks whether the date falls on a weekend.

Program

day_of_week.py
from datetime import date
d = date(2026, 8, 15) # or: d = date(int(input("Year: ")), int(input("Month: ")), int(input("Day: ")))
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
print("Date:", d.strftime("%d %B %Y"))
print("weekday() number:", d.weekday()) # Monday is 0, Sunday is 6
print("Day of the week:", days[d.weekday()])
print("Using strftime:", d.strftime("%A"))
if d.weekday() >= 5:
print("It falls on a weekend")
else:
print("It falls on a weekday")
Output
Date: 15 August 2026
weekday() number: 5
Day of the week: Saturday
Using strftime: Saturday
It falls on a weekend

How it works

  1. d.weekday() returns a number from 0 to 6, where 0 is Monday and 6 is Sunday.
  2. That number is used as an index into the days list to get the day's name.
  3. strftime("%A") gives the full name in one step, and %a gives the short form, such as Sat.
  4. A weekday() of 5 or 6 means Saturday or Sunday, which is how the program spots a weekend: 15 August 2026, Independence Day, is a Saturday.

Other ways to write it

Using Zeller's congruence

Using Zeller's congruence
def day_of_week(day, month, year):
# Zeller's formula counts January and February as months 13 and 14 of the year before
if month < 3:
month += 12
year -= 1
k = year % 100
j = year // 100
h = (day + 13 * (month + 1) // 5 + k + k // 4 + j // 4 + 5 * j) % 7
names = ["Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
return names[h]
print("15 August 2026 is a", day_of_week(15, 8, 2026))
print("26 January 1950 was a", day_of_week(26, 1, 1950))
Output
15 August 2026 is a Saturday
26 January 1950 was a Thursday

Zeller's congruence is a formula that finds the weekday with arithmetic alone, no modules needed. Its answer h counts from 0 for Saturday, which is why the names list starts there.

Using the calendar module

Using the calendar module
import calendar
for year in range(2026, 2031):
day = calendar.weekday(year, 8, 15) # Monday is 0
print("15 August", year, "is a", calendar.day_name[day])
Output
15 August 2026 is a Saturday
15 August 2027 is a Sunday
15 August 2028 is a Tuesday
15 August 2029 is a Wednesday
15 August 2030 is a Thursday

The calendar module has its own weekday() and a ready-made list of day names, handy for checking one date across several years.

Try it yourself

Find the day of the week you were born on.

Edit the program above and press Run, or open it in the full editor to save it and share it. To watch it run line by line, open it in the visualizer.

All Python programs · CBSE class 12 practical file · Python exercises