XPath/XQuery year-from-dateTime function

Summary

Returns the year component of an xs:dateTime.

Signature

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

Properties

This function is deterministic, context-independent, and focus-independent.

Rules

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise, the function returns an xs:integer representing the year component in the local value of $arg. The result may be negative.

Examples

The expression fn:year-from-dateTime(xs:dateTime("1999-05-31T13:20:00-05:00")) returns 1999.

The expression fn:year-from-dateTime(xs:dateTime("1999-05-31T21:30:00-05:00")) returns 1999.

The expression fn:year-from-dateTime(xs:dateTime("1999-12-31T19:20:00")) returns 1999.

The expression fn:year-from-dateTime(xs:dateTime("1999-12-31T24:00:00")) returns 2000.

The expression fn:year-from-dateTime(xs:dateTime("-0002-06-06T00:00:00")) returns -2.

Notes

Ignoring complications that arise with midnight on the last day of the year, the year returned is the same numeric value that appears in the lexical representation, which for negative years means the meaning may vary depending on whether XSD 1.0 or XSD 1.1 conventions are in use.