Hi France,
The function fn:years-from-duration is fairly basic; it only returns
the year component of your duration argument (as xs:dayTimeDuration
has none, in contrast to xs:yearMonthDuration). The background: A year
may have 365 or 366 days, and the duration is not sufficient to
compute the number of years.
You can use the average number of years for your computation if that’s
sufficient for your use case (see [1] for a variety of approximations
to choose from):
let $d1 := xs:date('2007-07-31')
let $d2 := xs:date('2019-12-06')
let $duration := $d2 - $d1
let $days := days-from-duration($duration)
return $days div 365.2425
Best,
Christian
[1] https://en.wikipedia.org/wiki/Year
On Fri, Dec 6, 2019 at 11:24 AM France Baril
<france.baril@architextus.com> wrote:
>
> Hi,
>
> The following function returns P4511D: 0 but I expect P4511D: 12
> Bug or bad usage?
>
>> let $d1 := xs:date('2007-07-31')
>> let $d2 := xs:date('2019-12-06')
>> let $duration := $d2 - $d1
>> let $years := years-from-duration($duration)
>> return $duration || ': ' || $years