ISO week date
The ISO week date is a standardized method for representing dates as defined in ISO 8601-1:2019, utilizing a week-based calendar where weeks begin on Monday and are numbered from 01 to 53 within a designated year, formatted as YYYY-Www-D (with YYYY as the four-digit week year, Www as the two-digit week number prefixed by 'W', and D as the weekday from 1 for Monday to 7 for Sunday).[1] This format ensures unambiguous international communication of dates, particularly useful in computing, data exchange, and scheduling systems that prioritize weekly cycles over monthly ones.[2]
Key rules for week numbering specify that week 01 of a year is the first week containing at least four days of that year, which is equivalently the week that includes the year's first Thursday; thus, it may start as early as the previous December 29 or as late as January 4.[1] Most years have 52 weeks spanning 364 days, but a 53-week year spans 371 days (53 weeks × 7 days), ensuring the calendar aligns closely with the Gregorian solar year while maintaining fixed seven-day weeks.[1] The week year may differ from the Gregorian calendar year, as dates near year-end or start can belong to the adjacent week year—for instance, December 31, 2022 (a Saturday), falls in 2023-W01-6, as the first week of 2023 begins on December 26, 2022.[1]
This system contrasts with traditional calendar dates (YYYY-MM-DD) by emphasizing weeks as the primary unit, reducing ambiguity in cross-cultural contexts where week starts vary (e.g., Sunday in some regions versus Monday in ISO).[2] Adopted widely in standards like XML Schema and programming libraries (e.g., Python's datetime module), the ISO week date facilitates precise temporal calculations, such as fiscal reporting or international trade, without reliance on locale-specific month lengths.[1] Extensions in ISO 8601-2:2019 allow for durations and intervals in week terms, enhancing its utility for recurring events.[3]
Fundamentals
Definition
The ISO week date is a convention for representing dates using the week-numbering year, a week number from 01 to 53, and a weekday number from 1 to 7, with Monday assigned the value 1 and Sunday 7.[4] This format, denoted as YYYY-Www-D, facilitates unambiguous identification of dates in a week-based structure.[5]
Defined within the ISO 8601 international standard, the ISO week date system was first published in 1988 to establish a uniform method for the representation of dates and times in data interchange, minimizing confusion across different cultural and regional conventions.[6] The standard was revised in 2000, again in 2004, and in 2019 (when it was split into ISO 8601-1 and ISO 8601-2) to refine its specifications, including enhancements to the week date components for greater clarity and applicability in computing and communication systems.[7][4][1]
A fundamental principle of the ISO week date is that all weeks commence on Monday, and the designated year—the week-year—may occasionally diverge from the corresponding Gregorian calendar year, particularly for dates near year boundaries.[5] For instance, 2023-W01-1 denotes January 2, 2023, which is the first Monday within the 2023 week-year.[8] This approach prioritizes the continuity of complete seven-day weeks over strict alignment with calendar year starts or ends.[9]
The ISO week date format, as defined in ISO 8601-1:2019, represents a specific date by combining the week-year (YYYY), the week number prefixed by 'W' (Www), and the day of the week (D).[1] The extended format uses hyphens as separators: YYYY-Www-D, where YYYY is the four-digit week-year, ww is the two-digit week number (padded with a leading zero if necessary), and D is the one-digit weekday (1 for Monday through 7 for Sunday).[10] For example, 2025-W45-3 denotes Wednesday in week 45 of the 2025 week-year.[11]
An alternative basic format omits the hyphens for compactness: YYYYWwwD.[10] In this notation, the same date as above would be written as 2025W453.[11] Both formats adhere to the principle of big-endian ordering, starting with the largest unit (year) and proceeding to the smallest (day).[1]
The week number ww ranges from 01 to 53, and the day D from 1 to 7, but not all combinations are valid since most years have only 52 weeks, making certain week 53 designations invalid for those years.[10] Week 53 occurs only in years with 53 weeks, typically when the Gregorian year starts or ends on a Thursday.[12] For instance, in the 1976 week-year, which has 53 weeks, 1976-W53-7 corresponds to December 31, 1976, illustrating how week 53 can align with the final days of the Gregorian year.[10] Year transitions are handled by assigning dates to the week-year that contains the majority of their days, ensuring continuity across calendar boundaries.[1]
Basic Rules
In the ISO week date system, weeks always begin on Monday and end on Sunday, with weekdays numbered from 1 (Monday) to 7 (Sunday).[9][13] This numbering ensures a consistent seven-day structure aligned with international business practices.[9]
A day is assigned to the ISO week that contains its Thursday, meaning the week spans from the Monday to the Sunday including that Thursday.[13][9] The first week (W01) of a given week-year is the one that includes the first Thursday of the corresponding Gregorian year, guaranteeing at least four days of the new year in that initial week.[13]
The week-year may differ from the Gregorian calendar year due to these alignments, particularly at year boundaries. Days before the first Thursday in January belong to the previous week-year's final week, while days after the last Thursday in December belong to the next week-year's first week.[9] For instance, December 31, 2012 (a Monday), falls in the first week of the 2013 week-year as 2013-W01-1, since it is the Monday of the week containing the first Thursday of 2013 (January 3).[14] This distinction between week-year and calendar year prevents split weeks and maintains the integrity of full seven-day periods.[9]
The ISO week date is typically notated as YYYY-Www-D, where YYYY is the week-year, ww is the two-digit week number (01-53), and D is the weekday (1-7).[15]
Relation to the Gregorian Calendar
Week Boundaries
In the ISO week date system, defined by ISO 8601-1:2019, the first week of a week-year (week 01) is the week containing the first Thursday of the corresponding Gregorian year.[1] This rule ensures that week 01 always includes at least four days—Monday through Thursday—in the new Gregorian year.[5] Equivalently, week 01 is the week that contains January 4 of the Gregorian year, as this date invariably falls within the first ISO week.[5] The week begins on the Monday of that period, aligning with the standard that all ISO weeks start on Monday.[1]
For example, in 2025, January 1 is a Wednesday, making January 2 the first Thursday of the year. Therefore, 2025-W01 runs from Monday, December 30, 2024, to Sunday, January 5, 2025, with the first three days belonging to the previous week-year.[16]
The last week of an ISO week-year, either week 52 or 53, concludes on the Sunday preceding the Monday that initiates week 01 of the subsequent week-year.[5] This boundary ensures continuity across week-years without overlap or gap. An ISO week-year spans 52 weeks in most cases but extends to 53 weeks when the Gregorian year includes 53 Thursdays, a configuration that occurs approximately 17.75% of the time and is more frequent in leap years due to the additional day affecting weekday alignment.[17][18]
Weeks per Year
In the ISO week date system, most week-years contain 52 full weeks, totaling 364 days, though some extend to 53 weeks, encompassing 371 days.[9] This variation arises because the Gregorian calendar year has 365 or 366 days, which do not align perfectly with multiples of 7-day weeks; an extra week is included when the week-year boundaries capture an additional Thursday.[17]
A week-year has 53 weeks if it begins on a Thursday in a common year or on a Wednesday in a leap year, ensuring the inclusion of the leap week (the 53rd).[9] These 53-week years occur approximately every 5 to 6 years, with a frequency of about 17.75% over the long term, influenced by the Gregorian leap year cycle and the 400-year rule.[17] For instance, the 2026 week-year starts on a Thursday (December 29, 2025, to January 4, 2026, as week 1) and includes 53 weeks.[19]
The Doomsday rule from the Gregorian calendar provides a quick method to identify potential 53-week years by calculating the weekday for key dates like January 1, allowing verification of the starting condition without full calendars.
In business and fiscal contexts, 53-week years impact reporting under 52-53 week fiscal calendars, which often align with ISO week numbering for consistent weekly periods; the extra week can shift quarterly alignments and complicate year-over-year financial comparisons, requiring adjustments in budgeting and tax planning.[20]
Weeks per Month
In the ISO week date system, Gregorian months exhibit variable distribution of weeks due to the fixed Monday-starting weeks that frequently cross month boundaries, resulting in months spanning 4 to 6 distinct ISO weeks.[13] This variability arises from the combination of month lengths (28 to 31 days) and the alignment of the first Thursday of the year, which determines week 1 and influences edge months.[13]
Patterns in this distribution show that mid-year months like July, with 31 days, often contain more full weeks, while shorter months like February typically span fewer, around 4 weeks.[21] January and December, as edge months, commonly include partial weeks from the adjacent year; for instance, January 2025 encompasses parts of five ISO weeks—2025-W01 (starting December 30, 2024) through 2025-W05 (extending to February 2, 2025)—with only three full weeks entirely within the month.[21] Over the long term, the average number of ISO weeks per Gregorian month is approximately 4.35, derived from the calendar's mean annual length of 365.2425 days divided by 7 days per week and then by 12 months.[22]
This irregular alignment complicates monthly week-based scheduling and reporting, as partial weeks disrupt consistent planning across fiscal or operational periods that blend monthly and weekly views.[23]
Fixed Week Dates
In the ISO week date system, certain Gregorian dates serve as reliable anchors because they consistently belong to the same designated week number each year, facilitating quick orientation in perpetual calendars and almanacs without requiring complex computations.[5]
January 4 is always part of week 01, regardless of the starting day of the year.[5] This invariance stems directly from the definition of week 01 as the week containing the year's first Thursday, which equivalently ensures inclusion of January 4 since the possible positions of that Monday-starting week place it between December 29 of the prior year and January 4.[5] The weekday position of January 4 within week 01 varies from Monday (day 1) to Sunday (day 7), depending on the configuration.[24]
Symmetrically, December 28 always falls in the final week of the ISO year, which is either week 52 or 53.[25] According to the ISO 8601 standard, this results from the last week's definition as the one containing the year's final Thursday, equivalently encompassing December 28 to guarantee at least four days in the year.[25] Like January 4, its weekday position in that week ranges from 1 to 7.[24]
These two dates provide up to seven fixed reference points annually when considering their potential weekday alignments across the week's structure, enabling users to anchor and extend week numbering forward or backward for practical reference in scheduling and fiscal planning.[26]
Equal Weeks
In the ISO week date system, equal weeks refer to those that encompass the identical set of Gregorian calendar dates—specifically, the same month and day numbers from December 28 to January 3—but are designated as part of different ISO week-years. These weeks always begin on a Monday and end on a Sunday, spanning the year-end boundary, and arise exclusively in years with 53 weeks, where the additional week aligns December 28 as the starting Monday.[27][28]
A prominent example is ISO week 53 of 2015, which ran from December 28, 2015 (Monday) to January 3, 2016 (Sunday). This exact same Gregorian date range—December 28 through 31 followed by January 1 through 3—reappeared as ISO week 53 of 2020, from December 28, 2020 (Monday) to January 3, 2021 (Sunday). Such alignments occur under specific conditions tied to the Gregorian calendar's leap year cycle and starting weekday: common years beginning on Thursday, or leap years beginning on Wednesday, both resulting in 53 weeks and positioning December 28 as Monday for the final week.[27][28][9]
In contrast, other 53-week configurations produce different but recurring date spans for their 53rd week. For instance, leap years starting on Thursday, such as 2004, feature week 53 from December 27, 2004 (Monday) to January 2, 2005 (Sunday), repeating this pattern in similarly configured future years. These equal weeks are relatively rare, appearing in the approximately 17.75% of years that have 53 weeks, which happens roughly every 5 to 6 years on average due to the 7-day week cycle against the 365- or 366-day Gregorian year.[29][9][30]
This phenomenon aids pattern recognition in long-term datasets, such as financial reporting or epidemiological tracking, where recurring year-end date clusters allow consistent aggregation without adjusting for varying week counts. Unlike fixed week dates, which anchor individual days (e.g., all Mondays) to consistent positions within the ISO structure, equal weeks emphasize the full 7-day sequence matching across years, providing a broader temporal equivalence.[9]
Advantages and Applications
Key Benefits
The ISO week date system establishes a standardized approach to week numbering by defining all weeks to begin on Monday and consist of exactly seven days, thereby minimizing ambiguity in international communications, business transactions, and data interchange. This consistency facilitates seamless global collaboration, as it eliminates variations arising from differing national conventions on week starts and boundaries.[5][31]
A key advantage lies in its simplicity for week-based calculations, as no week is split across months or years—each fully belongs to a single calendar year. This structure simplifies processes such as payroll computation, workforce scheduling, and development of ISO-compliant software, where precise week aggregation is essential for accuracy and efficiency.[26]
Furthermore, the Monday-start convention aligns closely with prevalent workweek patterns in many regions, supporting a typical five-day cycle from Monday to Friday followed by a weekend. Historically, the system was formalized in ISO 8601:1988 to supersede disparate earlier standards and national practices, thereby enhancing worldwide interoperability in commerce, administration, and technology since its adoption.[15][31]
Practical Uses
In business and finance, ISO week dates facilitate the structuring of fiscal quarters around complete weeks, such as the common 13-week quarters used in retail and manufacturing for consistent financial reporting and budgeting.[32] Retail inventory cycles frequently align with ISO week-based calendars, like the 4-5-4 or 4-4-5 systems, to synchronize stock management, sales forecasting, and promotional planning across fixed seven-day periods without partial weeks disrupting metrics.[33]
In computing and programming, ISO week dates are implemented through standard libraries to handle temporal data accurately; for instance, Python's datetime module includes the isocalendar() method, which returns the ISO year, week number, and weekday for any given date, enabling reliable week-based aggregations in data analysis and scheduling applications.[34] Database systems adhere to ISO week numbering for timestamps to support interoperable queries and reporting.[34]
ISO week dates underpin international standards for data exchange, particularly in Electronic Data Interchange (EDI) via UN/EDIFACT, where elements like Data Element 2379 specify calendar week days in a year-week-day format with weeks starting on Monday (though week numbering differs from ISO 8601 by defining week 01 as the first week of January) for standardized business documents.[35] In logistics, this format appears in shipping manifests and supply chain documentation to denote delivery weeks unambiguously across borders, while the European Union incorporates ISO 8601 through its harmonized standard EN ISO 8601 for regulatory compliance in trade and administrative processes.
Practical examples include Microsoft Excel's WEEKNUM function with return_type=21, which computes ISO week numbers to align spreadsheets with international fiscal reporting.[36] Similarly, global application APIs, such as those following RESTful design principles, employ ISO week date notation (e.g., YYYY-Www) for endpoints handling scheduling or analytics, ensuring chronological sorting and cross-timezone consistency in distributed systems.[37]
Comparisons with Other Systems
Differences from Gregorian Week Numbering
The ISO week date system, defined by ISO 8601, diverges from traditional Gregorian week numbering primarily in the definition of the week's starting day and the assignment of weeks to calendar years. In the ISO system, weeks begin on Monday and are numbered from 1 to 52 or 53, with the first week of the year being the one that includes the first Thursday of January (or equivalently, contains at least four days of the new year). By contrast, many implementations of Gregorian week numbering, such as in the United States, start weeks on Sunday, and the numbering often ties directly to the calendar year without adjusting for partial weeks at the boundaries.[9][26]
A key difference lies in year assignment: the ISO week-year is the Gregorian year containing the Thursday of that week, which can cause dates in late December or early January to belong to a different year than their Gregorian date. For instance, if December 29 to December 31 falls on a Monday to Wednesday, those days are assigned to week 1 of the following ISO year, even though they are part of the prior Gregorian year ending December 31. In standard Gregorian week numbering, all dates from January 1 to December 31 are confined to that calendar year, with week 1 typically starting from or near January 1, potentially resulting in partial weeks at the beginning or end of the year.[38]
Specific examples illustrate these shifts. December 31, 2000, a Sunday, falls on the seventh day of week 52 in ISO year 2000 (2000-W52-7), aligning with the Gregorian year. However, December 30, 2019, a Monday, is the first day of week 1 in ISO year 2020 (2020-W1-1), despite being the 364th day of Gregorian 2019. In Gregorian numbering, December 30, 2019, would be near the end of week 52 of 2019, fixed to that year.[39][40]
These differences can lead to confusion in international or mixed systems, such as business reporting or software applications, where a date like December 31 might be interpreted as belonging to one year in ISO but another in local Gregorian conventions, potentially causing errors in week-based aggregations. The ISO approach mitigates certain issues inherent in Gregorian numbering, such as the absence of a "week 0" or "week 54," by ensuring all weeks are fully contained within 1 to 53 and aligned to whole weeks without partial orphans at year ends.[9][26]
Other Week Numbering Systems
The Julian Day Number (JDN) provides a continuous, uninterrupted count of days originating from noon Universal Time on January 1, 4713 BCE (proleptic Julian calendar), facilitating precise chronological calculations in astronomy without reliance on calendar discontinuities like month or year boundaries.[41] This system enables the derivation of week numbers through integer division of the JDN by 7, yielding a sequential week count extending backward and forward indefinitely from the epoch, while the remainder (JDN modulo 7) identifies the day within the week, with conventions typically assigning 0 to Monday and progressing to 6 for Sunday.[42] For instance, the first day of ISO week 2025-01 (Monday, December 30, 2024) corresponds to JDN 2460675, placing it in week number 351,525 from the Julian epoch (exactly divisible by 7), and modulo 7 yields 0, confirming Monday under the standard astronomical mapping.[41]
In the United States, fiscal week numbering systems, particularly prevalent in retail and manufacturing, diverge from calendar-based weeks by prioritizing consistent quarterly reporting through structures like the 4-4-5 calendar adopted by the National Retail Federation (NRF).[43] This framework divides the fiscal year into four quarters of exactly 13 weeks each (totaling 52 weeks, with a 53rd week inserted every five to six years to align with the 365- or 366-day solar year), where each quarter comprises three fiscal "months": two of 4 weeks and one of 5 weeks, often starting weeks on Sunday to match consumer shopping patterns.[43] Weeks are numbered sequentially from 1 to 52 (or 53) within the fiscal year, which typically begins the Sunday nearest January 31 (late January or early February), ensuring even quarters have balanced durations for sales comparisons; for example, in a 53-week fiscal 2025 under NRF guidelines, the extra week is added to the fourth quarter to maintain quarterly equivalence without shifting prior periods.[43]
Variants of ISO 8601-inspired week numbering exist in North American contexts, where weeks often commence on Sunday rather than Monday, adapting the sequential numbering to align with local conventions while retaining the principle of a year starting with the week containing January 1. In such systems, week 1 is the first week with at least one day in the new year (or a majority, depending on the implementation), leading to potential offsets from the ISO scheme; for instance, software like Microsoft Excel uses a Sunday-start variant where the week number for a given date follows a 1-based count from January 1, differing from ISO by up to one week in boundary cases.
Historical alternatives include the French Revolutionary calendar (1793–1805), which replaced the seven-day week with the décade, a 10-day cycle divided into three phases per 30-day month, eliminating traditional weekly numbering in favor of a decimal-based structure to symbolize rational reform.[44] Each décade culminated in a rest day (décadi), with days named sequentially (primidi for the first, duodi for the second, up to décadi), and the year structured around 12 months plus five or six complementary days, resulting in no fixed seven-day weeks but a continuous 10-day rhythm for civil and festival purposes.[44]
Algorithms
Week Number from Ordinal Date
The ISO week number from a Gregorian ordinal date, consisting of a year Y and day of the year D (ranging from 1 to 365 or 366), is determined by aligning D with the start of the first ISO week, which is defined as the week containing January 4 of year Y. This adjustment accounts for the Thursday rule, ensuring that January 4 always falls within week 1 of the ISO year. The process begins by identifying the position of January 4 (ordinal day 4) and computing an offset based on its weekday to locate the Monday that begins the first week.
To compute the offset, first determine the weekday of January 4 in year Y, denoted as w (where Monday = 1, Tuesday = 2, ..., Sunday = 7). The offset to the first Monday is then $4 - ((w - 1) \mod 7), which may yield a value between -2 and 4. This offset represents the day-of-year position of the Monday starting ISO week 1 relative to January 1. If the offset is positive and greater than 1, early days in January belong to the previous ISO year; if negative, the ISO year begins before January 1, incorporating late December days from the prior Gregorian year into week 1 of Y.[45]
The provisional week number is calculated using the formula:
\text{week} = \left\lfloor \frac{D - \text{offset}}{7} \right\rfloor + 1
where D is the day of the year and offset is as defined above. This formula measures complete weeks from the first Monday. Boundary handling is essential: if the computed week is 0 (typically for D < 4 when the first Thursday falls after January 4), the date belongs to the previous ISO year, and the week number is 52 or 53 depending on whether the previous year has 53 weeks (determined by checking if December 31 of Y-1 falls in a week starting in Y-1). Conversely, for late-year dates ( D > 360 in non-leap years or > 361 in leap years), if the computed week exceeds 52 or 53 and the week containing the date has its Thursday in the next Gregorian year, the date shifts to week 1 of the next ISO year. 53-week years occur in about 18% of years (71 out of 400), specifically when the Gregorian year starts or ends such that the total spans an extra week.[45]
Pseudocode for the core logic, assuming a function to compute the weekday of January 4:
function isoWeekFromOrdinal(Y, D):
w = weekdayOfDate(Y, 1, 4) // 1=Monday to 7=Sunday
offset = 4 - ((w - 1) % 7)
provisional_week = floor((D - offset) / 7) + 1
iso_year = Y
if provisional_week < 1:
// Early days: shift to previous year
iso_year = Y - 1
// Compute weeks in previous year (52 or 53)
prev_w = weekdayOfDate(Y-1, 12, 31)
has_53_weeks = (prev_w == 4 or prev_w == 5) // Thursday or Friday for Dec 31
provisional_week = (has_53_weeks ? 53 : 52) + provisional_week // Adjust to last week
elif provisional_week > 53:
// Late days: check spill to next year
next_offset = 4 - ((weekdayOfDate(Y+1, 1, 4) - 1) % 7)
days_in_year = 365 + (isLeap(Y) ? 1 : 0)
if D > days_in_year - next_offset + 1:
iso_year = Y + 1
provisional_week = 1
else:
// Clamp to 52 or 53 based on year length
curr_w = weekdayOfDate(Y, 12, 31)
has_53_weeks = (curr_w == 4 or curr_w == 5)
provisional_week = min(provisional_week, has_53_weeks ? 53 : 52)
return (iso_year, provisional_week)
function isoWeekFromOrdinal(Y, D):
w = weekdayOfDate(Y, 1, 4) // 1=Monday to 7=Sunday
offset = 4 - ((w - 1) % 7)
provisional_week = floor((D - offset) / 7) + 1
iso_year = Y
if provisional_week < 1:
// Early days: shift to previous year
iso_year = Y - 1
// Compute weeks in previous year (52 or 53)
prev_w = weekdayOfDate(Y-1, 12, 31)
has_53_weeks = (prev_w == 4 or prev_w == 5) // Thursday or Friday for Dec 31
provisional_week = (has_53_weeks ? 53 : 52) + provisional_week // Adjust to last week
elif provisional_week > 53:
// Late days: check spill to next year
next_offset = 4 - ((weekdayOfDate(Y+1, 1, 4) - 1) % 7)
days_in_year = 365 + (isLeap(Y) ? 1 : 0)
if D > days_in_year - next_offset + 1:
iso_year = Y + 1
provisional_week = 1
else:
// Clamp to 52 or 53 based on year length
curr_w = weekdayOfDate(Y, 12, 31)
has_53_weeks = (curr_w == 4 or curr_w == 5)
provisional_week = min(provisional_week, has_53_weeks ? 53 : 52)
return (iso_year, provisional_week)
This pseudocode handles year shifts by boundary conditions near January (days 1–3) and December (days ~361–366), ensuring the Thursday rule is respected. Computing weekdays requires a separate algorithm, such as approximating the Julian day number for year Y, month 1, day 1, then deriving w = (( \text{julian_day} + 1 ) \mod 7) + \text{adjustment} for the numbering scheme.[45]
For example, consider the ordinal date 2025-1 (January 1, 2025, a Wednesday). The weekday of January 4, 2025 (a Saturday, w = 6) gives offset = 4 - (5 % 7) = 4 - 5 = -1. Then, provisional_week = \lfloor (1 - (-1)) / 7 \rfloor + 1 = \lfloor 2 / 7 \rfloor + 1 = 0 + 1 = 1, with ISO year 2025 (no shift needed, as the first week starts December 30, 2024, but belongs to 2025 due to containing January 4). Thus, it is 2025-W1. In contrast, for cases like January 1, 2023 (a Sunday), the offset leads to provisional_week = 0, shifting to 2022-W52.[45]
Week Number from Calendar Date
To derive the ISO week number from a Gregorian calendar date consisting of year, month, and day, the process begins by computing the ordinal date, or day of the year, which represents the cumulative number of days elapsed since January 1 of that year. This ordinal date serves as an intermediate step before applying the week calculation from the ordinal date, as detailed in the preceding section on algorithms. The approach ensures compatibility with the ISO 8601 standard's definition of weeks, where the week number aligns with the year containing the majority of the week or specifically the Thursday of that week.[46]
The ordinal date is obtained by adding the day of the month to the total number of days in all preceding months within the year. The days in preceding months are determined using a fixed array of month lengths under the Gregorian calendar: January (31), February (28 or 29 in leap years), March (31), April (30), May (31), June (30), July (31), August (31), September (30), October (31), and November (30). This yields the following cumulative days to the start of each month in non-leap years:
| Month | Cumulative Days (Non-Leap) |
|---|
| January | 0 |
| February | 31 |
| March | 59 |
| April | 90 |
| May | 120 |
| June | 151 |
| July | 181 |
| August | 212 |
| September | 243 |
| October | 273 |
| November | 304 |
| December | 334 |
The ordinal date is then calculated as the cumulative value for the given month plus the day.[46]
Leap years require an adjustment: if the year is a leap year and the month is after February (i.e., month > 2), add 1 to the cumulative days before adding the day to account for the extra day in February. A year is a leap year in the Gregorian calendar if it is divisible by 4, but not by 100 unless also divisible by 400. This adjustment ensures the ordinal date correctly reflects the position within the 366-day year.[46][4]
Once the ordinal date is determined, the ISO week number and associated year are computed using the ordinal-based algorithm, which incorporates the weekday of the date to identify the Monday-starting week containing the ISO Thursday. Dates near year boundaries, particularly December 29 through 31, may belong to the following year's week 1 if the majority of that week (including its Thursday) falls in the next year, or to the previous year's week 52 or 53 otherwise. Similarly, January 1 through 3 may fall into the previous year's final week.[46]
For instance, January 1, 2017 (month 1, day 1; non-leap year, ordinal date 1) results in ISO week 52 of 2016, as this date falls in the week starting December 26, 2016 (with Thursday on December 29, 2016). Another example is December 31, 2009 (month 12, day 31; non-leap year, ordinal date 365), which yields ISO week 53 of 2009, since 2009 contained 53 weeks due to starting on a Thursday, and December 31 falls in the final week with its Thursday on December 31 itself.
Calendar Date from Week Number
To convert an ISO week date, specified as the ISO year Y, week number W (ranging from 01 to 53), and weekday D (1 for Monday to 7 for Sunday), to a corresponding Gregorian calendar date (calendar year, month, and day), the process involves calculating an intermediate ordinal day number relative to January 1 of year Y, adjusting for potential year boundary crossings, and then mapping the ordinal to the month and day within the appropriate calendar year. This algorithm relies on the ISO 8601 definition that week 01 of the ISO year Y is the week containing January 4 of Y, with its Thursday falling between January 1 and January 7 of Y.
The first step is to determine the weekday of January 4 in year Y using Zeller's congruence adapted for the Gregorian calendar, which provides a mathematical formula to compute the day of the week for any date. For January 4 (m=13, year adjusted to y = Y-1, day q=4), let K = (Y-1) \mod 100 and J = \lfloor (Y-1)/100 \rfloor. The congruence is given by
h \equiv q + \left\lfloor \frac{13(m+1)}{5} \right\rfloor + K + \left\lfloor \frac{K}{4} \right\rfloor + \left\lfloor \frac{J}{4} \right\rfloor + 5J \pmod{7},
where h = 0 corresponds to Saturday, 1 to Sunday, ..., 6 to Friday. The ISO weekday d (1=Monday, ..., 7=Sunday) is then
d = ((h + 5) \mod 7) + 1.
This yields the position of January 4 within its week.[47]
Next, compute the ordinal day number (1 for January 1) of the Thursday (day 4) in week 01 relative to January 1 of Y:
\text{ordinal}_{\text{Thu, W01}} = 8 - d.
The ordinal day number for the target date Y-W-D relative to January 1 of Y is
\text{ordinal} = \text{ordinal}_{\text{Thu, W01}} + 7(W - 1) + (D - 4).
This formula adds the weeks from week 01 to week W (shifting to the Thursday of week W) and then adjusts from Thursday to the target weekday D.[45]
If \text{ordinal} \geq 1 and \text{ordinal} \leq 365 (or 366 if Y is a leap year, determined by Y \mod 4 = 0 and not a century year unless Y \mod 400 = 0), the calendar year is Y. If \text{ordinal} < 1, the date falls in the previous year (Y-1), and the adjusted ordinal is \text{ordinal} + number of days in Y-1 (365 or 366). If \text{ordinal} > 365 (or 366), it falls in the next year (Y+1), with adjusted ordinal \text{ordinal} - days in Y. Year shifts occur for early weeks in years starting mid-week (e.g., week 01 spilling into December of the prior year) or late weeks in years ending mid-week.
To convert the final ordinal \text{ordinal}' in calendar year C to month and day, compare against cumulative days from January, accounting for leap year if applicable:
| Month | Cumulative Days (Non-Leap) | Cumulative Days (Leap) |
|---|
| January | 31 | 31 |
| February | 59 | 60 |
| March | 90 | 91 |
| April | 120 | 121 |
| May | 151 | 152 |
| June | 181 | 182 |
| July | 212 | 213 |
| August | 243 | 244 |
| September | 273 | 274 |
| October | 304 | 305 |
| November | 334 | 335 |
| December | 365 | 366 |
Find the smallest month M where cumulative days to end of M \geq \text{ordinal}', then day = \text{ordinal}' - cumulative to end of M-1. For example, in a non-leap year, ordinal 32 falls in February (day 32 - 31 = 1).[45]
Consider the example of 2025-W01-1. Year 2025 is non-leap. January 4, 2025, is a Saturday (d=6), so \text{ordinal}_{\text{Thu, W01}} = 8 - 6 = 2 (January 2). Then, \text{ordinal} = 2 + 7(1-1) + (1-4) = -1. Since negative, shift to 2024 (leap, 366 days): \text{ordinal}' = -1 + 366 = 365. Cumulative to November 30 is 335, to December 31 is 366, so month=December, day=365 - 335 = 30. Thus, December 30, 2024. This illustrates a year shift for the first Monday of 2025's week 01.