Description
The fn:months-from-duration function calculates the months component of a normalized xs:duration value, as an integer between -11 and 11 inclusive. This is not necessarily the same as the integer that appears before the M in the value. For example, if the duration is P18M , the function returns 6 rather than 18. This is because 12 of those months are considered to be one year, and the normalized value is therefore P1Y6M .
For a function that returns the total number of months as a decimal number, see functx:total-months-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 |
---|
months-from-duration(
xs:yearMonthDuration('P3M')) |
3 |
months-from-duration(
xs:yearMonthDuration('-P18M')) |
-6 |
months-from-duration(
xs:yearMonthDuration('P1Y')) |
0 |
months-from-duration(
xs:yearMonthDuration('P12M')) |
0 |
See AlsoHistory |
Recommended Reading:
|