months-from-duration

The number of months in a duration

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.

Parameters

Description

arg:numeric()

Examples

XPath

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 Also