Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Isocalendar() Method Of Datetime Class In Python

  • Last Updated : 23 Aug, 2021

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

Note:

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

  • 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 year can start as yearly as 29th January or as late as 4th January of a Gregorian calendar.
  • 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: Using today’s dates.

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: Using 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
Recommended Articles
Page :

Start Your Coding Journey Now!