isocalendar() Function Of Datetime.date Class In Python
The isocalendar() function is used to return a tuple containing 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 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: Get ISO Year, ISO Week Number, and ISO Weekday.
Python3
from datetime import date
Todays_date = date.today()
print (Todays_date)
print (Todays_date.isocalendar())
|
Output:
2021-07-25
(2021, 29, 7)
Example 2: Get ISO Year, ISO Week Number, and ISO Weekday with a specific date.
Python3
from datetime import date
A = date( 2020 , 10 , 11 )
Date = A.isocalendar()
print ( "Original date:" ,A)
print ( "Date in isocalendar is:" , Date)
|
Output:
Original date: 2020-10-11
Date in isocalendar is: (2020, 41, 7)
Last Updated :
28 Jul, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...