The weekday function in Python

The python weekday function of class date returns the day of the week as an integer. It starts from 0 for a Sunday and ends at 6 for a Saturday

Date Updated 10 Feb 2017 1 min read

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 ValueDay of the week
0Monday
1Tuesday
2Wednesday
3Thursday
4Friday
5Saturday
6Sunday

Example

python
# 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

Output
This year's Christmas is on a Monday

Next new year is on a Monday