XPath/XQuery subtract-dates function


Returns the xs:dayTimeDuration that corresponds to the elapsed time between the starting instant of $arg2 and the starting instant of $arg2.

Operator Mapping

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


$arg1 as xs:date,
$arg2 as xs:date
) as xs:dayTimeDuration


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


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 starting instant of an xs:date is the xs:dateTime at 00:00:00 on that date.

The function returns the result of subtracting the two starting instants using op:subtract-dateTimes.

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


Assume that the dynamic context provides an implicit timezone value of Z.

The expression op:subtract-dates(xs:date("2000-10-30"), xs:date("1999-11-28")) returns xs:dayTimeDuration("P337D").

Now assume that the dynamic context provides an implicit timezone value of +05:00.

The expression op:subtract-dates(xs:date("2000-10-30"), xs:date("1999-11-28Z")) returns xs:dayTimeDuration("P336DT19H").

The expression op:subtract-dates(xs:date("2000-10-15-05:00"), xs:date("2000-10-10+02:00")) returns xs:dayTimeDuration("P5DT7H").