Hello,
Spreadsheet (version 4.1.7) contains 52 tabs, one per week.
Function WEEKNUM needs to return year (4 digits), <week> as a written word, week number (2 digits).
I entered =YEAR(C2)&"week" &WEEKNUM(C2; 2) which gives me without spaces: 2024week1
However output should read: 2024 week 1
1) How can I alter the formula so as to add single spaces in between?
2) How to add a leading zero to week number 1 up to week number 9?
3) The formula does work, but does it look crisp and elegant as well (not sure)?
Thanks.
[Solved] WEEKNUM + text
[Solved] WEEKNUM + text
Last edited by Hagar Delest on Sun May 12, 2024 9:01 pm, edited 1 time in total.
- MrProgrammer
- Moderator
- Posts: 4948
- Joined: Fri Jun 04, 2010 7:57 pm
- Location: Wisconsin, USA
Re: weeknum + text
WEEKNUM only returns the week number. WEEKNUM cannot provide the year, nor can it add text. To put 2024 week 01 in a cell, you must use the YEAR function and the concatenation operator, as you have done.
=YEAR(C2)&" week "&TEXT(WEEKNUM(C2;2);"00")
Any crisp and elegant formulas would be of little value if you don't understand how they work. The formula above is what I would use. Parameter 00 tells the TEXT function to format the week number as two digits.
To learn more about the WEEKNUM function see sections E and F in [Tutorial] Calc date formulas. Perhaps you want WEEKNUM_ADD instead of WEEKNUM or you want type 1 instead of type 2. Those sections explain the differences.
If this solved your problem please go to your first post use the Edit ☐ button and add [Solved] to the start of the Subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
Re: WEEKNUM + text
I had been searching for answers in excel help forums. I would not have figured out placing the bit TEXT the way you did.
Thanks a lot.
Thanks a lot.
Re: [Solved] WEEKNUM + text
Hallo
Code: Select all
=TEXT(C2; "yyyy \w\e\e\k ww")
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
- MrProgrammer
- Moderator
- Posts: 4948
- Joined: Fri Jun 04, 2010 7:57 pm
- Location: Wisconsin, USA
Re: [Solved] WEEKNUM + text
Number format code WW gives the value of WEEKNUM(date;1) and uses 1 digit for the first nine weeks. Poster amDEwolff asked for WEEKNUM(date;2) and 2-digit numbers for those weeks.
=YEAR("2024-01-07")&" week "&TEXT(WEEKNUM("2024-01-07";2);"00") → 2024 week 01 =TEXT("2024-01-07";"YYYY \w\e\e\k WW") → 2024 week 2
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
Re: [Solved] WEEKNUM + text
I cannot see any difference between (except 1st returns Text and the 2nd returns numeric values:MrProgrammer wrote: ↑Mon May 13, 2024 4:13 amNumber format code WW gives the value of WEEKNUM(date;1) and uses 1 digit for the first nine weeks. Poster amDEwolff asked for WEEKNUM(date;2) and 2-digit numbers for those weeks.
=YEAR("2024-01-07")&" week "&TEXT(WEEKNUM("2024-01-07";2);"00") → 2024 week 01 =TEXT("2024-01-07";"YYYY \w\e\e\k WW") → 2024 week 2
Code: Select all
=TEXT(A2; "ww" )
=WEEKNUM(A2;2)
Code: Select all
Version: 7.4.7.2 / LibreOffice Community
Build ID: 40(Build:2)
CPU threads: 4; OS: Linux 6.6; UI render: default; VCL: gtk3
Locale: de-DE (de_DE.UTF-8); UI: de-DE
Debian package version: 4:7.4.7-1+deb12u1
Calc: threaded
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
- MrProgrammer
- Moderator
- Posts: 4948
- Joined: Fri Jun 04, 2010 7:57 pm
- Location: Wisconsin, USA
Re: [Solved] WEEKNUM + text
That's interesting. They are the same for you. But they are different for me. For both of us =WEEKNUM("2024-01-07";2) is numeric 1. For you, =TEXT("2024-01-07";"WW") is text 1. But for me, =TEXT("2024-01-07";"WW") is text 2 because the result of format code WW depends on the locale! Mine is English (Canada).
Code WW does not pad single-digit weeks with a leading zero, as other codes like MM and DD do, so WW doesn't seem like a good solution for amDEwolff.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).