In this tutorial, I will explain how to get the day of the week from a date using Python. I encounter this scenario when working with dates in a Python projects for one of my New York clients. We will explore different methods to accomplish this, including using the built-in datetime module and the calendar module with examples.
datetime Module in Python
The datetime module in Python provides classes for working with dates and times. To get started, let’s import the necessary classes from the datetime module:
from datetime import date, datetimeWe’ll primarily use the date class for our examples, but the datetime class can also be used when dealing with both date and time information.
Read How to Implement the Sigmoid Activation Function in Python?
1. Use the weekday() Method
The date class provides a convenient method weekday() that returns an integer representing the day of the week. The integer values range from 0 to 6, where Monday is 0 and Sunday is 6. Here’s an example:
# Create a date object
my_date = date(2023, 7, 4) # July 4, 2023
# Get the day of the week (0-6)
day_of_week = my_date.weekday()
print(day_of_week) Output:
1I have executed the above example and added the screenshot below.

In this example, we created an date object representing July 4, 2023, which is Independence Day in the United States. We then used the weekday() method to get the corresponding day of the week as an integer. The output is 1, indicating that July 4, 2023, falls on a Tuesday.
Check out __new__ vs __init__ in Python
2. Map Integer Values to Day Names
While the weekday() method returns an integer, you may want to display the actual day name (e.g., “Monday”, “Tuesday”) to make it more readable. You can achieve this by creating a mapping between the integer values and the day names. Here’s an example:
# Create a mapping of integer values to day names
day_names = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
# Create a date object
my_date = date(2023, 11, 23) # November 23, 2023 (Thanksgiving)
# Get the day of the week (0-6)
day_of_week = my_date.weekday()
# Get the corresponding day name
day_name = day_names[day_of_week]
print(day_name) Output:
ThursdayI have executed the above example and added the screenshot below.

In this example, we created a list called day_names that maps the integer values (0-6) to their corresponding day names. We then used the weekday() method to get the integer value for November 23, 2023 (Thanksgiving in the United States) and used that value to retrieve the corresponding day name from the day_names list.
Read Python Class Method vs Static Method
3. Use the isoweekday() Method
Another useful method provided by the date class is isoweekday(). It works similarly to weekday(), but it returns an integer representing the day of the week according to the ISO 8601 standard. In this standard, Monday is represented by 1, and Sunday is represented by 7. Here’s an example:
# Create a date object
my_date = date(2023, 12, 25) # December 25, 2023 (Christmas)
# Get the ISO weekday (1-7)
iso_weekday = my_date.isoweekday()
print(iso_weekday) Output:
1I have executed the above example and added the screenshot below.

In this example, we created an date object for December 25, 2023 (Christmas Day). We then used the isoweekday() method to get the corresponding ISO weekday value, which is 1, indicating that Christmas falls on a Monday in 2023.
Read How to Use the Mean() Function in Python?
Formate Date Strings
Sometimes, you may have a date represented as a string in a specific format, such as “YYYY-MM-DD”. To convert this string into an date object, you can use the datetime.strptime() function. Here’s an example:
# Date string in the format "YYYY-MM-DD"
date_string = "2023-01-01" # January 1, 2023 (New Year's Day)
# Convert the date string to a date object
my_date = datetime.strptime(date_string, "%Y-%m-%d").date()
# Get the day of the week (0-6)
day_of_week = my_date.weekday()
print(day_names[day_of_week]) Output:
SundayIn this example, we have a date string in the format “YYYY-MM-DD” representing January 1, 2023 (New Year’s Day). We used the datetime.strptime() function to parse the string and create an datetime object, specifying the format of the string using the "%Y-%m-%d" format specifier. We then extracted the date object from the datetime object using the date() method.
Finally, we used the weekday() method to get the integer value of the day of the week and retrieve the corresponding day name from the day_names list.
Check out What is Python Return Statement?
Use the calendar Module in Python
Python’s calendar module provides additional functionality for working with dates and calendars. It offers a weekday() function that takes a year, month, and day as arguments and returns the day of the week as an integer (0 for Monday, 6 for Sunday). Here’s an example:
import calendar
# Get the day of the week (0-6)
day_of_week = calendar.weekday(2023, 2, 14) # February 14, 2023 (Valentine's Day)
print(day_names[day_of_week]) Output:
TuesdayIn this example, we used the calendar.weekday() function to get the day of the week for February 14, 2023 (Valentine’s Day). We passed the year, month, and day as separate arguments to the function, and it returned the integer value representing the day of the week. We then used that value to retrieve the corresponding day name from the day_names list.
Check out How to Create a Square Function in Python?
Handle Leap Years
When working with dates, it’s important to consider leap years. Leap years have an extra day (February 29) to keep the calendar in sync with the Earth’s rotation around the sun. Python’s date and datetime classes automatically handle leap years correctly. Here’s an example:
# Create a date object for a leap year
leap_year_date = date(2024, 2, 29) # February 29, 2024 (Leap Year)
# Get the day of the week (0-6)
day_of_week = leap_year_date.weekday()
print(day_names[day_of_week]) Output:
ThursdayIn this example, we created an date object for February 29, 2024, which is a valid date in a leap year. We used the weekday() method to get the corresponding day of the week, and it correctly identified February 29, 2024, as a Thursday.
Read How to Use Counter Function in Python?
Conclusion
In this tutorial, I explained how to get the day of the week from a date using Python. We explored different methods to achieve this task. We learned how to use the weekday() and isoweekday() methods from the datetime module, as well as the calendar.weekday() function from the calendar module. We also covered how to map integer values to day names and handle leap years correctly.
You may also like to read:
- How to Use Exponential Functions in Python?
- How to Use the find() Function in Python?
- How to Use Built-In Functions in Python?

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.