XML technologies / XSLT / XSLT and XPath functions / Alphabetical XSLT and XPath reference / hours-from-dateTime

(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 5, translated from German)

A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z

fn:hours-from-dateTime

Category:

Value extraction from time values, date values and duration

Origin:

XPath 2.0

Return value:

An integer of xs:integer type which corresponds to the value of the hours component within the timestamp value passed on.

Call/Arguments:

fn:hours-from-dateTime($timestampValue)

$timestampValue:

Optional. A timestamp value of xs:dateTime type which may include a timezone indication. If the empty sequence is passed on, the function also returns an empty output sequence.

Purpose of use:

The function returns an integer between inclusive 0 to 23 which corresponds to the value of the hours component of the timestamp value passed on of xs:dateTime type. The value is normalised beforehand, which means the timezone factor is included (see examples). This may cause a date jump to the previous day or to the next day, provided that the normalised daytime portion does not fall below the value T00:00:00 or does not exceed the value T23:59:59 because of the timezone correction factor. In this case, another value is outputted as the possibly expected (see example 2).

Example 1 - hours from timestamp value, version 1:

fn:hours-from-dateTime(

xs:dateTime("2007-07-10T10:20:00-05:00")

)

Results in: 15.

The inclusion of the timezone correction factor results in a hour value of 15. Here, no date jump occurs.

Example 2 - hours from timestamp value, version 2:

fn:hours-from-dateTime(

xs:dateTime("2007-07-10T21:30:00-05:00")

)

Results in: 2.

In this case, during the normalisation the correction factor of the timezone causes a date jump to the next day T02:30:00.

Example 3 - hours from timestamp value, version 3:

fn:hours-from-dateTime(

xs:dateTime("2007-07-10T12:00:00")

)

Results in: 17.

When having an assumed implicit timezone factor of -5:00, in this example the value 17 becomes the result by subtracting the appropriate correction factor of -5:00 from 12 - (-5:00).

Function definition:

XPath 1.0:

The function is not available.

XPath 2.0:

fn:hours-from-dateTime($arg as xs:dateTime?) as xs:integer?

   

 

 

 

back to top