Function Name
weekday
Function Signature
weekday()
Function Overview
The weekday() function of date class in datetime module, returns an integer corresponding to the day of the week. Here is the mapping of integer values to the days of the week.
| Integer Value | Day of the week |
| 0 | Monday |
| 1 | Tuesday |
| 2 | Wednesday |
| 3 | Thursday |
| 4 | Friday |
| 5 | Saturday |
| 6 | Sunday |
Example
# import Python's datetime module
import datetime
# weekdays as a tuple
weekDays = ("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")
# Find out what day of the week is this year's Christmas
thisXMas = datetime.date(2017,12,25)
thisXMasDay = thisXMas.weekday()
thisXMasDayAsString = weekDays[thisXMasDay]
print("This year's Christmas is on a {}".format(thisXMasDayAsString))
# Find out what day of the week next new year is
nextNewYear = datetime.date(2018,1,1)
nextNewYearDay = nextNewYear.weekday()
nextNewYearDayAsString = weekDays[nextNewYearDay]
print("Next new year is on a {}".format(nextNewYearDayAsString))Output
This year's Christmas is on a Monday
Next new year is on a Monday