Description
The fn:hoursfromduration function calculates the hours component of a normalized xs:duration value, as an integer between 23 and 23 (inclusive). This is not necessarily the same as the integer that appears before the H in the value. For example, if the duration is PT1H90M , the function returns 2 rather than 1. This is because 90 minutes is equal to 1.5 hours, and the normalized value is therefore PT2H30M . Likewise, if the duration is PT36H , the result is 12, because the normalized value is P1DT12H .
This is in contrast to the functx:totalhoursfromduration function, which would return 2.5 in the first case, and 36 in the second case.
For a function that returns the total number of hours as a decimal number, see functx:totalhoursfromduration.
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 

hoursfromduration(
xs:dayTimeDuration('P1DT5H')) 
5 
hoursfromduration(
xs:dayTimeDuration('PT36H')) 
12 
hoursfromduration(
xs:dayTimeDuration('PT1H90M')) 
2 
hoursfromduration(
xs:dayTimeDuration('PT2H59M')) 
2 
hoursfromduration(
xs:dayTimeDuration('PT3600S')) 
1 
See AlsoHistory 
Recommended Reading:
