The isocalendar()
function returns a named tuple containing year, week number, and weekday in
python isocalendar()
It does not take any argument value.
tuple
: This method will return the tuple containing year, and week number, day of the week in ISO format.In the code below, we will fetch today’s date and then map it into the ISO standard time notation:
# Import the date module from datetimefrom datetime import date# Call the today() method that returns today's datetoday = date.today()# Print today's dateprint("Today's date=", today)# Call the isocalendar() method over today variable# to get its ISO Year, Week Number and Weekdayprint('ISO notation: (Year, Week Number, Week Day)=', today.isocalendar())
The code above will convert Gregorian date to ISO date formate.
date.today()
returns the current date in today
variable.print("Today's date=", today)
prints today’s date on console.isocalendar()
method to convert today
date to ISO formate and prints the results on the console.# Import date module from datetimefrom datetime import date# make demo date variable_date = date(2019, 9, 22)# Call the isocalendar() method over the above-mentioned defined dateISO_date = _date.isocalendar()#Print real date and its ISO Year, Week Number, and Weekdayprint("The original date is:",_date)print("Date by using isocalendar method is:", ISO_date)
The code below shows the isocalender()
method that converts user-defined Date to ISO format.
_date
variable to specified date i.e., date(2019, 9, 22)
.isocalender()
method._date
variable.ISO_date
variable.