fn:years-from-duration function
The fn:years-from-duration function returns the years component of a duration.
Syntax
- duration-value
- The duration value from which the years component is to be extracted.
duration-value is an empty sequence, or is a value that has one of the following types: xs:dayTimeDuration, xs:duration, or xs:yearMonthDuration.
Returned value
- If duration-value is of type xs:yearMonthDuration or is of type xs:duration, the returned value is of type xs:integer. The value is the years component of duration-value cast as xs:yearMonthDuration. The value is negative if duration-value is negative.
- If duration-value is of type xs:dayTimeDuration, the returned value is of type xs:integer and is 0.
- If duration-value is an empty sequence, the returned value is an empty sequence.
The years component of duration-value cast as xs:yearMonthDuration is the integer number of years determined by the total number of months of duration-value cast as xs:yearMonthDuration divided by 12.
Examples
The following function returns the years component of the duration -4 years, -11 months, and -320 days.
fn:years-from-duration(xs:duration("-P4Y11M320D"))The returned value is -4.
The following function returns the years component of the duration 9 years and 13 months.
fn:years-from-duration(xs:yearMonthDuration("P9Y13M"))The returned value is 10. When calculating the total number of years in the duration, 13 months is converted to 1 year and 1 month. The duration is equal to P10Y1M which has a years component of 10 years.
