What is the date.fromisocalendar() method in Python?

The fromisocalendar() method transforms a date in the Gregorian calendar format to an equivalent date in the ISOInternational Organization for Standardization calendar format. This date is defined by the year, the week number, and the day of the week.

Note: The Gregorian calendar is the calendar that is currently in use all over the world.

Syntax


date.fromisocalendar(year, week, day)

Parameters

This method returns the ISO calendar date that is equivalent to the given Gregorian calendar date, according to these specified parameters:

  • year: It takes the year number as integer type value.
  • week: It takes the week number, with ranges [1 to 52 or 53], as an argument.
  • day: It also takes the number of the day of the week, with ranges [1 to 7], as an argument.

Return value

This method returns the Gregorian calendar date, which will be equivalent to the date in the ISO calendar. In the example below, the 2021,12,18 Gregorian calendar date is equivalent to the 2021,50,6 ISO calendar date.

In the following example, fromisocalendar() will convert this 2021,50,6 date in ISO to its equivalent date in the Gregorian calendar and return it.

Note: The reverse method of fromisocalendar() is date.isocalendar().

Example

from datetime import date
# According to 18/12/2021, its 50th week going on
today= date(2021,12,18)
print("TODAY'S DATE:", today)
# As ISO week consist of 52 to 53 weeks per year
# and it's 50th week(18/12/2021) Why? According to ISO
# christmas is celebrated in 51th week
iso_today = date.fromisocalendar(today.year ,50 ,6)
print("Date equivalent to ISO calendar:", iso_today)
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources