# xf:dayTimeDuration

Converts $string-var (a string in the dayTimeDuration format) to the dayTimeDuration data type.

If $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

### Signatures

xf:dayTimeDuration(xs:string $string-var) —> xf:dayTimeDuration

### Arguments

Data Type | Argument | Description
--- | --- | ---
xs:string | $string-var | Represents a string with the duration specified with one of the following formats: d DT h H i M s S -d DT h H i M s S Note: Specifying the number days, hours, minutes, or seconds is optional—any of the substrings: dD, hH, iM, or sS do not have to be specified. For example, the following are valid durations: P10Y, P1D, -P11M, -P10Y7D, P2YT5H, or P6YT5H10S.
- | Duration is a negative amount of time. Note: If - is not specified, duration is a positive amount of time.
P | The start of a duration string. The P must always be specified.
d D | d—number of days in the duration.
D—days are specified in the duration.
T | The start of the time part of the duration string. The T must be specified if any minutes, hours, or seconds (hH, iM, or sS) are specified.
h H | h—number of hours in the duration.
H—years are specified in the duration.
i M | i—number of minutes in the duration.
M—minutes are specified in the duration.
s S | s—number of seconds in the duration.
S—seconds are specified in the duration.

### Returns

Returns a duration of time as a dayTimeDuration value.

### Examples

#### dayTimeDuration with All Components

Invoking dayTimeDuration("P4DT9H8M20S") returns a dayTimeDuration value corresponding to 4 days, 9 hours, 8 minutes, and 20 seconds, as shown in the following example query:

    let $mydur := xf:dayTimeDuration("P4DT9H8M20S")
    return
    <components>
    	<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>
    </components>

The preceding query, generates the following XML result:

    <components>
    	<days>4</days>
    	<hours>9</hours>
    	<minutes>8</minutes>
    	<seconds>20</seconds>
    </components>

#### dayTimeDuration with Just Hours and Seconds

Invoking dayTimeDuration("PT2H20S") returns a dayTimeDuration value corresponding to 2 hours and 20 seconds, as shown in the following example query:

    let $mydur := xf:dayTimeDuration("PT2H20S")
    return
    <components>
    	<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>
    </components>

The preceding query, generates the following XML result:

    <components>
    	<days>0</days>
    	<hours>2</hours>
    	<minutes>0</minutes>
    	<seconds>20</seconds>
    </components>

#### dayTimeDuration with Just Negative Days

Invoking dayTimeDuration("-P10D") returns a dayTimeDuration value corresponding to negative 10 days, as shown in the following example query:

    let $mydur := xf:dayTimeDuration("-P10D")
    return
    <components>
    	<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>
    </components>

The preceding query, generates the following XML result:

    <components>
    	<days>-10</days>
    	<hours>0</hours>
    	<minutes>0</minutes>
    	<seconds>0</seconds>
    </components>

Related Topics

W3C dayTimeDuration data type description.