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.
This description is © Copyright 2007, Priscilla Walmsley. It is excerpted from the book XQuery by Priscilla Walmsley, O'Reilly, 2007. For a complete explanation of this function, please refer to Appendix A of the book. Arguments and Return TypeName | Type |
$arg |
xs:duration? |
return value |
xs:integer? |
ExamplesXPath Example | 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 |
See AlsoHistory |
Recommended Reading:
|