Open In App

Isocalendar() Method Of Datetime Class In Python

Last Updated : 23 Aug, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The isocalendar() function is used to return a tuple of 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 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)


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads