Xquery用于计算两个日期之间的工作日,但结果错误

问题描述 投票:0回答:1

在 Informatica 中,我在应用程序集成过程中构建了这行 Xquery 代码:

fn:sum(for $j in 0 to fn:days-from-duration(xs:date($temp.t_laatsteLeverDatum) - fn:current-date()) 
return if (fn:day-from-date(fn:current-date() + xs:dayTimeDuration(concat('P', $j, 'D'))) < 6) then 1 else 0)

它计算今天与名为 t_laatsteLeverDatum(最后交货日期)的给定日期之间的工作日数。 今天是 2024 年 10 月 25 日,最晚交货日期为 2024 年 11 月 6 日。当使用上面的代码行时,结果应该是 13 天减去 4 个周末 = 9。但无论我做什么,我得到的结果都是 5。

然后我尝试了:

fn:count(
  for $i in 0 to fn:days-from-duration(xs:date($temp.t_dateRequestedJDE) - fn:current-date())
  let $day := fn:current-date() + xs:dayTimeDuration(concat('P', $i, 'D'))
  where fn:day-from-date($day) lt 6
  return $day
)

但这仍然会导致 5 个而不是 9 个。我错了什么,或者如何获得从现在到给定交货日期之间的正确工作日数?

xquery informatica
1个回答
0
投票

在我看来,您正在尝试计算距离

fn:current-date()
6 或更少的天数:

$temp.t_laatsteLeverDatum) - fn:current-date()

或这里

let $day := fn:current-date() + xs:dayTimeDuration(concat('P', $i, 'D'))
where fn:day-from-date($day) lt 6

因此您现在可以在哪里检查工作日,这就是您需要与

6
进行比较的内容。希望这有帮助。

接下来看看这篇文章

© www.soinside.com 2019 - 2024. All rights reserved.