Home »
Python »
Python Reference »
Python date Class
Python date isocalendar() Method with Example
Python date.isocalendar() Method: Here, we are going to learn about the isocalendar() method of date class in Python with its definition, syntax, and examples.
Submitted by Hritika Rajput, on April 29, 2020
Python date.isocalendar() Method
date.isocalendar() method is used to manipulate objects of date class of module datetime.
It uses a date class object and returns a 3-tuple (ISO year, ISO week number, ISO weekday).
Most of the date and time calendar follow the Gregorian calendar. The ISO calendar is a widely used variant of the Gregorian one. The ISO year consists of 52 or 53 full weeks, and where a week starts on a Monday and ends on a Sunday. The first week of an ISO year is the first (Gregorian) calendar week of a year containing a Thursday. This is called week number 1, and the ISO year of that Thursday is the same as its Gregorian year.
For example, 2004 begins on a Thursday, so the first week of ISO year 2004 begins on Monday, 29 Dec 2003 and ends on Sunday, 4 Jan 2004:
Weekday number for Monday is 1 while incrementing by 1 for the coming days.
Module:
import datetime
Class:
from datetime import date
Syntax:
isocalendar()
Parameter(s):
Return value:
The return type of this method is a tuple which tells us what is the ISO year, ISO week and the ISO weekday of that date.
Example:
## importing date class
from datetime import date
## Creating an instance
x = date.today()
d = x.isocalendar()
print("Original date:",x)
print("Today's date in isocalendar is:", d)
print()
x = date(2020, 1, 1)
d = x.isocalendar()
print("Date ", x,"in isocalendar is:", d)
print()
x = date(2020, 10, 27)
d = x.isocalendar()
print("Original date was:",x)
print("ISO year:",d[0],"ISO week:",d[1],"ISO weekday:",d[2])
Output
Original date: 2020-04-29
Today's date in isocalendar is: (2020, 18, 3)
Date 2020-01-01 in isocalendar is: (2020, 1, 3)
Original date was: 2020-10-27
ISO year: 2020 ISO week: 44 ISO weekday: 2