addDays doesn't work

Hi,

I’ve got the formula

{{get(split(“Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag,Sonntag”; “,”); formatDate(toString(now); “d”))}}

Bildschirmfoto 2023-01-16 um 09.38.57

and want to change it to
{{get(split(“Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag,Sonntag”; “,”); formatDate(toString(addDays(now; 6)); “d”))}}

Bildschirmfoto 2023-01-16 um 09.38.39

But somehow the day of the week doesn’t got shown …

Why?
What is it, what I don’t understand? :thinking:

Thank you in advance and best regards
Martin

Hi @Martin,

Thank you for sharing your question and the formula you’re trying to modify. To debug this issue, it’s helpful to split the complete function and set the result as a variable. By checking the results of each function and the function descriptions, it’s easier to identify the problem.

From analyzing your formula, it appears that the issue is with the last variable, where you are trying to retrieve the current day of the week. From the documentation, it seems that Sunday is considered the first day of the week and it is indexed as 0. However, in your array of days in the week, the index starts with 1. This can be seen in the following image:


image

To fix this issue, you should change the order of the days in the string so that Sunday is the first day, and add 1 to the result of the second parameter in the get() function. The updated formula should look like this:

{{get(split("Sonntag,Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag"; ","); sum(formatDate(toString(addDays(now; 6)); "d"); 1))}}

I also wrote an article on the topic of zero-based and one-based indexing in Make, which you might find helpful: Mastering the slice function in Make: Understanding zero-based and one-based indexing

Please let me know if you have any further questions.

Glenn - Callinetic

2 Likes

Thank you Glenn,

It works and now I got an idea why
{{formatDate(toString(addDays(now; 6)); “DD.”)}}
had worked on the other side.
Both formulas seemed to be similar – but in combination with a get-function I have to keep in mind that it is working with index.
:blush:

Best regards
Martin