You say you have a vacationRequest object with a startdate and an endate. Now dates always have a time part also included but let's say we do not take that into account but I would then make sure that the timepart are always set to the beginning of the day and make sure that all dates are UTC. Now to count the days make a variable and fill it with the startdate. Then check if this date is a saterday or a a sunday. There are multiple ways to do this and you already found a way. If it is not a saterday or sunday raise the daycounter with one. Then hange the variable and use the addDaysUTC to add one day to the variable. Then check if this day is after the endate and if not return to the beginning of the flow just before where you check if it is a saterday or sunday. This loop will continue untill the variable is later then the startdate and then you have your correct day count.
Hope this helps and regards,
Ronald
Wouldn't it be easier to first calculate the total number of days between the two dates using the Between Date Function Call and correcting the result with the number of weekend days between the start and end date?
For example, there are 14 days between 5 and 19 november. Both start and end days are Tuesdays, so there are 4 weekend days in between, which makes for a total of 10 week days.
If one or more of the start or end days is a weekend day, the calculation is a bit more complex, but it would also start with the daysBetween() function. Using a modulo calculation can be used to see if the number of days is a multiple of 7 ($Result mod 7 = 0) or one/two less than a multiple of 7 ($Result mod 7 = 6 or 5), which would reduce the number of weekend days in between with one or two, respectively.