Skip to content
Related Articles
Open in App
Not now

Related Articles

isocalendar() Function Of Datetime.date Class In Python

Improve Article
Save Article
  • Last Updated : 28 Jul, 2021
Improve Article
Save Article

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

Note:

  • According to ISO standard 8601 and ISO standard 2015, Thursday is the middle day of a week.
  • Therefore, ISO years always start with Monday.
  • ISO years can have either 52 full weeks or 53 full weeks.
  • ISO years do not have any fractional weeks during the beginning of the year or at the end of the year.

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




# 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




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

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!