addDays doesn't work

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