79136025

Date: 2024-10-29 06:27:14
Score: 3
Natty:
Report link

@Maciejg, thanks for your last reply. I was once told that it's not common for topic starters to answer their topics that way, that's why.

The code I use now is:

let $referenceDate := xs:date("2024-01-01")
let $daysInWeek := 7
let $startDate := fn:current-date()
let $endDate := xs:date($temp.t_laatsteLeverDatum) (: or $temp.t_dateRequestedJDE :)

return if (
    fn:sum(
        for $i in 0 to fn:days-from-duration($endDate - $startDate)
        let $currentDate := $startDate + xs:dayTimeDuration(concat('P', $i, 'D'))
        let $daysSinceReference := fn:days-from-duration($currentDate - $referenceDate)
        let $dayOfWeek := (1 + ($daysSinceReference mod $daysInWeek)) (: Convert to 1=Monday, ..., 7=Sunday :)
        return if ($dayOfWeek >= 1 and $dayOfWeek <= 5) then 1 else 0
    ) <= 3
) then 1 else 0

This code gave the expected 9 instead of 5. Unfortunately the simpler function fn:day-of-week() was not available in the environment I am working in.

Thanks for thinking along and your reactions and kind regards,

Aad

Reasons:
  • Blacklisted phrase (0.5): thanks
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (1): regards
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Maciejg
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Aad Dijksman