Open In App

isocalendar() Function Of Datetime.date Class In Python

The isocalendar() function is used to return a tuple containing ISO Year, ISO Week Number, and ISO Weekday.

Note:



Syntax: isocalendar()

Parameters: This function does not accept any parameter.



Return values: This function returns a tuple of ISO Year, ISO Week Number and ISO Weekday.

Example 1: Get  ISO Year, ISO Week Number, and ISO Weekday.




# Python3 code to demonstrate
# Getting a tuple of ISO Year, 
# ISO Week Number and ISO Weekday
  
# Importing date module from datetime
from datetime import date
   
# Calling the today() function
# to return todays date
Todays_date = date.today()
  
# Printing today's date
print(Todays_date)
  
# Calling the isocalendar() function
# over the above today's date to return
# its ISO Year, ISO Week Number
# and ISO Weekday
print(Todays_date.isocalendar())

Output:

2021-07-25
(2021, 29, 7)

Example 2:  Get ISO Year, ISO Week Number, and ISO Weekday with a specific date.




# Python3 code to demonstrate
# Getting a tuple of ISO Year, 
# ISO Week Number and ISO Weekday
  
# Importing date module from datetime
from datetime import date
   
# Creating an instance for 
# different dates
A = date(2020, 10, 11)
  
# Calling the isocalendar() function
# over the above specified date
Date = A.isocalendar()
  
# Printing Original date and its 
# ISO Year, ISO Week Number
# and ISO Weekday
print("Original date:",A)
print("Date in isocalendar is:", Date)

Output:

Original date: 2020-10-11
Date in isocalendar is: (2020, 41, 7)

Article Tags :