How do I get the day of week given a date in Python?


I want to find out the following: given a date (datetime object), what is the corresponding day of the week.

For instance Sunday is the first day, Monday: second day.. and so on

And then if the input is something like today's date.


>>> today = datetime.datetime(2017, 10, 20)
>>> today.get_weekday()  # what I look for

The output is maybe 6 (since its Friday)

10/25/2017 7:55:53 AM

Accepted Answer

Use weekday() (docs):

>>> import datetime
datetime.datetime(2012, 3, 23, 23, 24, 55, 173504)

From the documentation:

Return the day of the week as an integer, where Monday is 0 and Sunday is 6.

6/28/2012 8:59:57 AM

If you'd like to have the date in English:

from datetime import date
import calendar
my_date =
calendar.day_name[my_date.weekday()]  #'Wednesday'

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow