Date and time functions

WEEKNUM

Known larger differences on 443 of 13,339 recorded answers

Of 13,339 recorded answers (13,332 in the answer bank and 7 workbook cells), 443 do not match: 443 differ in kind or value. Excel's own recorded readings disagree with each other on 479 of these inputs. How we measure this · See the Rust code

Local names in 40 languages
LanguageName in Excel
ArabicWEEKNUM
BulgarianWEEKNUM
CzechWEEKNUM
DanishUGE.NR
GermanWEEKNUM
GreekWEEKNUM
English (Australia)WEEKNUM
English (United Kingdom)WEEKNUM
English (United States)WEEKNUM
SpanishNUM.DE.SEMANA
EstonianWEEKNUM
FinnishWEEKNUM
FrenchNO.SEMAINE
HebrewWEEKNUM
CroatianWEEKNUM
HungarianHÉT.SZÁMA
IndonesianWEEKNUM
ItalianWEEKNUM
JapaneseWEEKNUM
KoreanWEEKNUM
LithuanianWEEKNUM
LatvianWEEKNUM
NorwegianWEEKNUM
DutchWEEKNUM
PolishNUM.TYG
Portuguese (Brazil)WEEKNUM
Portuguese (Portugal)NÚMSEMANA
RomanianWEEKNUM
RussianНОМНЕДЕЛИ
SlovakWEEKNUM
SlovenianWEEKNUM
Serbian (Latin)WEEKNUM
SwedishVECKONR
ThaiWEEKNUM
TurkishHAFTASAY işlevi
UkrainianWEEKNUM
VietnameseWEEKNUM
Chinese (Simplified)WEEKNUM
Chinese (Hong Kong)WEEKNUM
Chinese (Traditional)WEEKNUM

Names from Microsoft's support site.

What it does

WEEKNUM(serial_number, [return_type])

WEEKNUM returns the ordinal number of the week within the year that a date falls in. The function carries two genuinely different definitions, selected by return_type, and confusing them is the source of nearly every disagreement between spreadsheets about "which week is it".

Microsoft states the two systems as follows:

  • System 1 — "The week containing January 1 is the first week of the year, and is numbered week 1." Under this system week 1 can be a stub of a single day, and a year can contain 54 partial weeks' worth of numbering in the worst case.
  • System 2 — "The week containing the first Thursday of the year is the first week of the year, and is numbered as week 1. This system is the methodology specified in ISO 8601, which is commonly known as the European week numbering system."

The documented return_type table:

return_typeWeek begins onSystem
1 or omittedSunday1
2Monday1
11Monday1
12Tuesday1
13Wednesday1
14Thursday1
15Friday1
16Saturday1
17Sunday1
21Monday2

Note the shape: nine of the ten options are System 1 and differ only in which weekday starts the week; the tenth, 21, is the ISO system and is the only one where the week-1 rule itself changes. return_type 2 and 11 are duplicates, as are 1 and 17 — the same redundancy the WEEKDAY table has, for the same historical reason.

Under System 1, the algorithm is: week n runs from the n-th week-start day on or before the first week-start day following 1 January, with the partial week containing 1 January counted as week 1. Under System 2 the algorithm is the ISO 8601 one, in which weeks always have seven days, always begin on Monday, and the last days of December can belong to week 1 of the following year — which is why an ISO week number alone is ambiguous without its ISO year.

Arguments

WEEKNUM(serial_number, [return_type]) — one required argument and one optional.

serial_number — "a date within the week". Microsoft's page repeats the serial-number model: "Excel stores dates as sequential serial numbers so they can be used in calculations. By default, January 1, 1900 is serial number 1." Supply dates from DATE or from another formula rather than as text.

return_type — optional; the week-start day and system, per the table. Omitted means 1 (weeks begin Sunday, System 1).

The misunderstood argument is again return_type, in three distinct ways: readers assume its values match WEEKDAY's (they overlap but do not mean the same thing), assume 21 is "just Monday" (it changes the entire week-1 rule), and assume there is a System 2 variant for other start days (there is not — ISO weeks are Monday-based by definition).

Try it

Input cells (optional)

Example: {"B2": 3, "B3": 4}. A1 holds the formula. Other cells need values before a formula can read them.

Enter a formula, then calculate.

Runs locally in your browser with OneCalc. Its answer may differ from Excel. Use English function names and commas between arguments.

Quirks

Result and edge cases

Returns a Number: a week ordinal.

  • Early January. This is where the two systems visibly disagree. A 1 January falling on a Friday is week 1 under System 1 and week 53 of the previous year under ISO.
  • Late December. Under System 1 a year can reach week 53 or 54 depending on the start day; under ISO the last days of December may be week 1 of the next year.
  • The result carries no year. WEEKNUM returns a number, not a (year, week) pair, so ISO week numbers obtained from it must be paired with an ISO year computed separately — Excel provides no ISO-year function.
  • Serials in 1900. Week numbering near the start of the serial line inherits the phase problem described on WEEKDAY, because week boundaries are weekday boundaries.

Errors

As documented on the Microsoft page:

  • #NUM! when serial_number is out of range for the current date-base value.
  • #NUM! when return_type is outside the range specified in the table.

Excel does not always follow the second of these: for an undocumented return_type it usually gives #NUM!, sometimes a number, and the same call can answer differently (FN-WEEKNUM-001).

Ordinary coercion failures give #VALUE!, and an error argument propagates; those are engine behaviours (see coercion and lifting), not WEEKNUM rules.

WEEKNUM with an invalid return_type can answer differently each time it is called

The documentation says an out-of-range return_type gives #NUM!. Excel usually does, but not always, and the same call can give different answers. In recorded captures of build 20430, 479 (serial_number, return_type) pairs were read with different results: usually #NUM!, sometimes a number (0, 1, 9, 10, 53 or 54), and some pairs differ within one run file. In build 20527 a matrix of 1,926 pairs (serial_number 0, 1, 59, 60, 61 and 43831, return_type -32 to 288) was read twice in one request, and 623 pairs differed between the two readings: 619 between a number and #NUM!, and 4 between 9 and 10. Every difference has an undocumented return_type. The ten documented return_types (1, 2, 11 to 17 and 21) gave the same answer both times. No rule for the undocumented values is claimed.

FormulaExcelMathematical value
WEEKNUM(0, 23)
Excel 16.0 build 20430, Windows 64-bit, CPU not recorded in this capture
Inputs and reference value

Number supplied through a cell.

serial_number: 0
0x0000000000000000

return_type: 23
0x4037000000000000

#NUM!—
WEEKNUM(0, 23)
Excel 16.0 build 20430, Windows 64-bit, CPU not recorded in this capture
Inputs and reference value

Number supplied through a cell.

serial_number: 0
0x0000000000000000

return_type: 23
0x4037000000000000

1
0x3ff0000000000000
—
WEEKNUM(0, 33)
Excel 16.0 build 20430, Windows 64-bit, CPU not recorded in this capture
Inputs and reference value

Number supplied through a cell.

serial_number: 0
0x0000000000000000

return_type: 33
0x4040800000000000

0
0x0000000000000000
—
WEEKNUM(0, 33)
Excel 16.0 build 20430, Windows 64-bit, CPU not recorded in this capture
Inputs and reference value

Number supplied through a cell.

serial_number: 0
0x0000000000000000

return_type: 33
0x4040800000000000

#NUM!—

Inputs, build details and evidence

How to implement

Notes for implementers

  1. Implement System 1 and System 2 as separate algorithms. They are not the same computation with a different start day; System 2's week 1 is defined by the first Thursday, System 1's by 1 January. A single parameterized routine that tries to cover both usually gets the year boundary wrong in one of them.
  2. Validate return_type against the exact set {1, 2, 11, 12, 13, 14, 15, 16, 17, 21}. It is not a range; 3 is valid for WEEKDAY and invalid here, which is a genuinely easy mistake given how the two tables are usually read side by side.
  3. Do not compute ISO weeks by rounding day-of-year. The standard ⌊(doy + 6 − isoweekday)/7⌋ style formula needs its year-boundary corrections; get them from the ISO definition rather than by patching failures.
  4. Reuse the weekday kernel shared with WEEKDAY, so that the 1900 phase behaviour is the same in both functions by construction rather than by coincidence.

Rust code

Show the CalcFunc source of this function

Quoted from the public repository DnaCalc/DnaCalc, crates calc-func and calc-fml, at commit 9e1884369a67. Comments are the source's own. A kernel shared with other functions appears once, on its module page.

WEEKNUM · 5 lines · calc-func/src/catalogue/dates.rs on GitHub
17 weeknum_fn "WEEKNUM" (1, 2) [V "serial_number", V "return_type"] |s, a, sv| {
    let serial = strict_date_arg(s, a, 0)?;
    let kind = return_type(s, a, true)?;
    out(s, k::weeknum(serial, kind))
}
weeknum · 15 lines · calc-func/src/ported/date_kernels.rs on GitHub
pub(crate) fn weeknum(serial: f64, return_type: Option<f64>) -> Result<f64, W> {
    let serial = whole_serial(serial)?;
    let return_type = whole(date_integer_floor(return_type.unwrap_or(1.0)))?;
    if return_type == 21 {
        return iso_weeknum_serial(serial);
    }
    if remap_weekday(1, return_type).is_none() || return_type == 3 {
        return Err(W::Num);
    }
    let (year, _, _) = ymd_1900(serial);
    let jan1 = serial_unbounded_1900(year, 1, 1);
    let jan1_weekday = weekday(jan1 as f64, Some(return_type as f64))? as i64;
    let week1_start = jan1 - (jan1_weekday - 1);
    Ok(((serial - week1_start).div_euclid(7) + 1) as f64)
}

Kernels shared with other functions

Argument and result plumbing

  • fail catalogue/kit
  • num catalogue/kit
  • out catalogue/kit

No implementation has been published with a Handbook test suite for this function.

Version differences

The recorded environments below distinguish a reading from a same-input comparison. Counts describe captured inputs in each environment; overlapping captures and comparisons are not totals of unique worksheet calls.

Excel 16.0 buildPlatform and CPUCaptured inputs
20430Windows, 64-bit, CPU not recorded13,332

The record contains no same-input comparison between these environments. Reading different inputs on different builds does not establish either a version change or cross-build agreement.

Recorded environments and comparison details.

Excel 16.0 build 20430

Windows 64-bit, CPU not recorded in this capture

WEEKNUM(0, 23) returned #NUM!. WEEKNUM(0, 23) returned 1 (0x3ff0000000000000). 2 further recorded controls are attached. Inputs were supplied through cells using Value2. These are controls from this environment, not a same-input comparison with another build.

Observed formulas and results
  • WEEKNUM(0, 23) → #NUM! (cell-value2)
  • WEEKNUM(0, 23) → 1
    0x3ff0000000000000 (cell-value2)
  • WEEKNUM(0, 33) → 0
    0x0000000000000000 (cell-value2)
  • WEEKNUM(0, 33) → #NUM! (cell-value2)

Excel 16.0 build 20430

Windows, 64-bit, CPU not recorded

13,332 captured inputs are indexed for this environment. Capture dates: 2026-09-29 to 2026-09-29. This is a reading count, not a comparison with another build.

Recorded variants

Excel buildCPURecorded behaviourOur RustEvidence
16.0 build 20430CPU not recorded (Windows, 64-bit)Two capture runs in one environment disagree on 479 recorded inputs: one recorded #NUM! where the other recorded a week number. The recorded cause is unresolved.One implementation can match only one reading of each conflicting input. CodeCalcFunc-Evidence · runs/w111-date-boundaries-20260929/answers/answers-weeknum.json.gz 4287ba192d2e3a7fd54671ea1cee1c34cb2e84e2 · compared with runs/w111-date-conversion-20260929/answers/answers-weeknum.json.gz

Alternatives

Relationships

  • ISOWEEKNUM — the dedicated ISO 8601 function, which on the documented reading computes the same thing as WEEKNUM(s, 21). Having two spellings of one definition is itself a fact about the surface, and whether they agree on every input is a natural equivalence test that nobody has run for this Handbook.
  • WEEKDAY — the day-of-week function whose return_type table looks similar and is not interchangeable.
  • DATE — the recommended way to construct the argument.
  • Confusable. WEEKNUM(s,1) and WEEKNUM(s,21) differ for a large fraction of January and December dates; reports that "Excel gives the wrong week number" are almost always this.

Named variants

No named variants are recorded yet.

Suggest a correction or contribute an implementation · For agents