years-from-duration
The number of years in a duration
Description
The fn:years-from-duration function calculates the years component of a normalized xs:duration value. This is not necessarily the same as the integer that appears before the Y in the value. For example, if the duration is P1Y18M, the function returns 2 rather than 1. This is because 18 months is equal to 1.5 years, and the normalized value is therefore P2Y6M.
For a function that returns the total number of years as a decimal number, see functx:total-years-from-duration.
Parameters |
Description |
---|---|
arg:numeric() |
Examples
XPath |
Results |
---|---|
years-from-duration(xs:yearMonthDuration(‘P3Y’)) |
3 |
years-from-duration(xs:yearMonthDuration(‘P3Y11M’)) |
3 |
years-from-duration(xs:yearMonthDuration(‘-P18M’)) |
-1 |
years-from-duration(xs:yearMonthDuration(‘P1Y18M’)) |
2 |
years-from-duration(xs:yearMonthDuration(‘P12M’)) |
1 |