The fromisocalendar()
method transforms a date in the Gregorian calendar format to an equivalent date in the
Note: The Gregorian calendar is the calendar that is currently in use all over the world.
date.fromisocalendar(year, week, day)
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.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()
isdate.isocalendar()
.
from datetime import date# According to 18/12/2021, its 50th week going ontoday= 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 weekiso_today = date.fromisocalendar(today.year ,50 ,6)print("Date equivalent to ISO calendar:", iso_today)