Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

fromisocalendar
python programming
communitycreator
python

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

Salman Yousaf

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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)

RELATED TAGS

fromisocalendar
python programming
communitycreator
python

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring