# xf:get-dayTimeDuration-from-dateTimes

Computes the time difference between $dateTime-var1 and $dateTime-var2 and returns it as a dayTimeDuration value.

If the value of $date-var1 follows in time the value of $date-var2, then the returned value is a negative duration.

If the value of $date-var1 or $date-var2 is the empty sequence, the following error is displayed:

    Error occurred while executing XQuery: Error loading the XQuery or XSLT for this method: Type error in function subtract-dates invocation: expected type [date@http://www.w3.org/2001/XMLSchema], given type empty

### Signatures

xf:get-dayTimeDuration-from-dateTimes(xs:dateTime $dateTime-var1, xs:dateTime $dateTime-var2) —> xf:dayTimeDuration

### Arguments

Data Type | Argument | Description
--- | --- | ---
xs:dateTime | $dateTime-var1 | Contains a representation of the date and time.
xs:dateTime | $dateTime-var2 | Contains a representation of the date and time.

### Returns

Returns the time difference between $dateTime-var1 and $dateTime-var2 as a dayTimeDuration value.

Returns a negative dayTimeDuration value if $dateTime-var1 follows in time $dateTime-var2. (The date specified in $dateTime-var1 comes before the date specified in $dateTime-var2.) To learn more, see the following Negative Difference example.

### Examples

#### Positive Difference

The following example query returns a positive days, hours, minutes, and seconds duration because the date specified in $datetime-var1 comes after the date specified in $datetime-var2:

    let $dateTime-var1 := xs:dateTime("2002-12-26T01:01:01")
    return
    let $dateTime-var2 := xs:dateTime("2001-11-26T00:00:00")
    return
    let $mydur := xf:get-dayTimeDuration-from-dateTimes($dateTime-var1, $dateTime-var2)
    return
    <result>
    	<days>{xf:get-days-from-dayTimeDuration($mydur)}</days>
    	<hours>{xf:get-hours-from-dayTimeDuration($mydur)}</hours>
    	<minutes>{xf:get-minutes-from-dayTimeDuration($mydur)}</minutes>
    	<seconds>{xf:get-seconds-from-dayTimeDuration($mydur)}</seconds>
    </result>

The preceding query generates the following result:

    <result>
    	<days>395</days>
    	<hours>1</hours>
    	<minutes>1</minutes>
    	<seconds>1</seconds>
    </result>

#### Negative Difference

The following example query returns a negative days, hours, minutes, and seconds duration because the date specified in $dateTime-var1 comes before the date specified in $dateTime-var2:

    let $dateTime-var1 := xs:dateTime("2001-11-26T00:00:00")
    return
    let $dateTime-var2 := xs:dateTime("2002-12-26T01:01:01")
    return
    let $mydur := xf:get-dayTimeDuration-from-dateTimes($dateTime-var1, $dateTime-var2)
    return
    <result>
    	<days>{xf:get-days-from-dayTimeDuration($mydur)}</days>
    	<hours>{xf:get-hours-from-dayTimeDuration($mydur)}</hours>
    	<minutes>{xf:get-minutes-from-dayTimeDuration($mydur)}</minutes>
    	<seconds>{xf:get-seconds-from-dayTimeDuration($mydur)}</seconds>
    </result>

The preceding query generates the following result:

    <result>
    	<days>-395</days>
    	<hours>-1</hours>
    	<minutes>-1</minutes>
    	<seconds>-1</seconds>
    </result>

Related Topics

W3C get-dayTimeDuration-from-dateTimes function description.

W3C dayTimeDuration data type description.

W3C dateTime data type description.