home contribute faq download

FunctX XSLT Functions

fn:years-from-duration

The number of years in a duration

Google
Webxsltfunctions.com

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 Type

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

Examples

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

functx:total-years-from-durationThe total number of years 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 XSLT Services

Recommended Reading:

XQuery