isoweekday function in Python

The isoweekday function of date class in Python returns the day of the week as an integer 1 for a Monday and 7 for a Sunday

Date Updated 10 Feb 2017 1 min read

Function Name

isoweekday

Function Signature

isoweekday()

Function Overview

The function isoweekday() returns an integer value corresponding to the day of the week. Unlike the date.weekday() function the date.isoweekday() function returns the value 1 for Monday and increments it by one for the subsequent days.

Here is the mapping table between integer values and ISO weekday.

Integer ValueDay of the week
1Monday
2Tuesday
3Wednesday
4Thursday
5Friday
6Saturday
7Sunday

Example

python
# import datetime module of Python

import datetime

daysOftheWeek = ("ISO Week days start from 1",

                "Monday",

                "Tuesday",

                "Wednesday",

                "Thursday",

                "Friday",

                "Saturday",

                "Sunday"

                )

# Christmas Eve

xmasEve     = datetime.date(2014,12,24)

isoWeekDay  = xmasEve.isoweekday()

print("Christmas Eve this year falls on a {}".format(daysOftheWeek[isoWeekDay]))

# Day after Christmas

dayAfterXmas     = datetime.date(2014,12,26)

isoWeekDay      = dayAfterXmas.isoweekday()

print("Day after Christmas this year falls on a {}".format(daysOftheWeek[isoWeekDay]))

Output

Output
Christmas Eve this year falls on a Wednesday

Day after Christmas this year falls on a Friday