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
Date: 15 August 2026 weekday() number: 5 Day of the week: Saturday Using strftime: Saturday It falls on a weekend
How it works
d.weekday()returns a number from 0 to 6, where 0 is Monday and 6 is Sunday.- That number is used as an index into the
dayslist to get the day's name. strftime("%A")gives the full name in one step, and%agives the short form, such as Sat.- 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
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
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.
Related programs
All Python programs · CBSE class 12 practical file · Python exercises