XPath/XQuery subtract-dateTimes function

Summary

Returns an xs:dayTimeDuration representing the amount of elapsed time between the instants arg2 and arg1.

Operator Mapping

Defines the semantics of the "-" operator when applied to two xs:dateTime values.

Signature

op:subtract-dateTimes(
$arg1 as xs:dateTime,
$arg2 as xs:dateTime
) as xs:dayTimeDuration

Properties

This function is deterministic, context-dependent, and focus-independent. It depends on implicit-timezone.

Rules

If either $arg1 or $arg2 do not contain an explicit timezone then, for the purpose of the operation, the implicit timezone provided by the dynamic context (See .) is assumed to be present as part of the value.

The function returns the elapsed time between the date/time instant arg2 and the date/time instant arg1, computed according to the algorithm given in Appendix E of , and expressed as a xs:dayTimeDuration.

If the normalized value of $arg1 precedes in time the normalized value of $arg2, then the returned value is a negative duration.

Examples

Assume that the dynamic context provides an implicit timezone value of -05:00.

The expression op:subtract-dateTimes(xs:dateTime("2000-10-30T06:12:00"), xs:dateTime("1999-11-28T09:00:00Z")) returns xs:dayTimeDuration("P337DT2H12M").