Error processing day of week on Calc

Hi to all,

I’m getting an error processing the day of week on Libreoffice Calc.

Here goes the error reproduction:

In cell A1:

05-03-2024

In cell D3:

=WEEKDAY(DATE(1;MONTH(A1);YEAR(A1));3)

It returns 3 (corresponding to Thursday) where it should return 4.

Is this a calculation error or Am I doing something wrong?

Thanks in advance

5 Likes

Yes.

Date

1 Like

5th of March 2024 is a Tuesday, therefore the correct result would be 1 with 0 to 6 representing Montay to Sunday.

1 Like

But May 3dh, 2024 is Friday. :grinning:

=WEEKDAY(“2024-3-5”;3) => 1
=WEEKDAY(“2024-5-3”;3) => 4

How does @Unkuiri get 3 (Thursday)?

Because arguments are out of order. See @JohnSUN comment.

Thanks…Too simple…Noob error… :face_with_hand_over_mouth:

To defend my honor I have to say that It was well done last year, but now Libreoffice was updated and does not open my file (it’s big…a all year schedule with calendars on each page… and then I have to open it on Openoffice and maybe it scrambbled the formulas… :stuck_out_tongue_winking_eye:

differentiate between format and formula, try the file:
LO_DATUM-Text-Numerus-weekday-calendar day.ods (15.4 KB)

1 Like

Hi Can you explain a little more the file you sent please? It seems useful for this or other implementations…I’ve done a schedule that automatically configures itself when I change the year and I’m trying to automatically mark the holidays and change the background colors for example…maybe your file helps…thanks…

The file demonstrates the difference between value and formatting.
Enter an ISO date in B5 order to make it work with any locale. “5.MäR.2024” works with German locale only. Enter “2024-3-5” instead. B5 is formatted as text (format code @). Anything you enter into that cell is treated literally.
D5 and D6 convert the text in B5 into a number.
WEEKDAY(D5) extracts the weekday number 3 from D5. The number format NNN (show weekday name) displays Tuesday for the number 3 which is totally wrong although it looks right. The day number 3 on Calc’s time scale happened to be a Tuesday just like 2024-03-05, but day number 3 was 1900-01-02. This happens to return the same weekday unless you change the calculation mode of the WEEKDAY function. WEEKDAY(D2;2) returns 2 (Monday=1) and the number format displays “Monday” for number 2 because Calc’s day number 2 (1900-01-01) was a Monday indeed. Never format any month number, year number or weekday number!
Cell E5 does it right. By reference it has the exact same cell value as D5. The number format “NNN” displays the correct weekday name, but this time it displays the weekday name of 2024-3-5 which is day number 45356.
G5 does the same. It references the same value 45356 in D5 and formats this number as DD showing the 2-digit day portion of the date. So does H5, I5 and J5. E5:J5 share the exact same value 45356. Due to formatting, they display only a partial information about the actual value.

The other part demonstrates how the WEEKDAY converts the date in D5 using different values for the second argument. See documentation on WEEKDAY

1 Like

My file above will be tested. It is imperfect.
A good way is to calculate any date in natural numeral after setting a DATUM in iSO 8601 format. Now I handle time only in fraction 45267 82000/86400 (= 2023-12-07T23:00:00), that result in a irrational number: 45257,968333333333333… . Every DATUM-formula or -format i use only to demonstrate last of any calculation. To control any result, I return it into the original number-time-date so it will be either correct or fault.

Irrational numbers are something different.

And with that you may defeat some mechanisms in Calc that detect when values formatted as date+time are used as operands with operator+ or operator- for example and try to eliminate some of the immanent precision round-off errors of binary floating point calculations.