How to Get the Day of Week Given a Date in Python

Created
Modified

Using weekday Method

The weekday() method returns the day of the week as an integer, where Monday is 0 and Sunday is 6.

The following example should cover whatever you are trying to do:

#!/usr/bin/python3

# Import module
import datetime
import calendar

d = datetime.datetime.today()
print(d.weekday())

# Monday
print(calendar.day_name[d.weekday()])
0
Monday

Using strftime Method

You can get the day of week given a date using the strftime Method. For example,

#!/usr/bin/python3

# Import module
import datetime

d = datetime.datetime.today()
print(d.strftime("%A"))
Monday

Related Tags

#get# #week#