WEEKNUM returns 1 for last day of year?

I’m very confused. Here is the version information:
Version: 25.8.1.1 (X86_64)
Build ID: 54047653041915e595ad4e45cccea684809c77b5
CPU threads: 16; OS: Windows 11 X86_64 (build 26100); UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: threaded

When I do =WEEKNUM(DATE(2025, 12, 31)) it gives 1. This is true for all dates up to the 28th, which is the american start to the last week of the year. It seems to never return 53 despite the documentation saying that it should.

Is this a known bug or am I using the function wrong.

https://help.libreoffice.org/25.8/en-US/text/scalc/01/func_weeknum.html?DbPAR=CALC#bm_id3159161

Yes I know I have read this. “the week containing january 1st is the 1st week of the year, and is numbered week 1”. The same documentation exists on excel’s website. The thing is if I copy the exact same formula into excel or sheets it gives me what I expect: 53.

=WEEKNUM(DATE(2033;12;31))

Okay so it works if the year ends on a saturday? The documentation says:
“WEEKNUM calculates the week number of the year for the internal date value as defined in ODF OpenFormula and compatible with other spreadsheet applications.”

Week number of the year should not return 1 for a day in december. If I to have leap weeks and stuff like that, that’s what ISOWEEKNUM is for. One would also think that the sentence “compatible with other spreadsheet applications” would mean it returns the same value as sheets/excel.

The openformula specification says for weeknum:

Returns the number of the week in the year for the given date

Number of the week in the year means that a partial week at the end of the year must be counted as still a week in that year.

This is in contrast to how they talk about isoweeknum:

ISO 8601 defines the calendar week as a time interval of seven calendar days starting with a Monday, and the first calendar week of a year as the one that includes the first Thursday of that year

If someone can explain to me how I read this incorrectly, please do

ask127197.ods (17.7 KB)

FTR: tdf#168576

You need to look what “Weeknum” you need. LibreOffice 25.8 provides to you: ISOWEEKNUM, WEEKNUM, WEEKNUM_EXCEL2003 and WEEKNUM_OOO. If you do not need special compatibilities, then ISOWEEKNUM will be the correct one.

1 Like

@Regina I see two problems here.

  1. WEEKNUM_EXCEL2003 doesn’t allow omitting its second argument, so is not actually implementing Excel’s counterpart.
  2. An XLSX created in Excel 2016, containing its WEEKNUM returning 53 there, imports as WEEKNUM, not WEEKNUM_EXCEL2003 → breaks compatibility. So indeed, that’s not a flaw in our WEEKNUM, but import filter problem - maybe needs a fix…