home contribute faq download

FunctX XQuery Functions

fn:months-from-duration

The number of months in a duration

Google
Webxqueryfunctions.com

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 Type

NameType
$arg xs:duration?
return value xs:integer?

Examples

XQuery ExampleResults
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 Also

functx:total-months-from-durationThe total number of months in a yearMonthDuration

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26W3C, XQuery 1.0 and XPath 2.0 Functions and Operators, http://www.w3.org/TR/xpath-functions/
Datypic XQuery Services

Recommended Reading:

XQuery