dayTimeDuration data type

The xdt:dayTimeDuration data type represents a duration of time that is expressed by days, hours, minutes, and seconds components. Derived from the xs:duration data type.

The range that can be represented by this data type is from -P83333333333333Y3M11574074074DT1H46M39.999999S to P83333333333333Y3M11574074074DT1H46M39.999999S (or -999999999999999 months and -999999999999999.999999 seconds to 999999999999999 months and 999999999999999.999999 seconds).

The lexical form of xdt:dayTimeDuration is PnDTnHnMnS, which is a reduced form of the ISO 8601 format. The following abbreviations describe this form:

P
The duration designator.
nD
n is an unsigned integer that represents the number of days.
T
The date and time separator.
nH
n is an unsigned integer that represents the number of hours.
nM
n is an unsigned integer that represents the number of minutes.
nS
n is an unsigned decimal that represents the number of seconds. If a decimal point appears, it must be followed by one to six digits that represent fractional seconds.
For example, the following form indicates a duration of 3 days, 10 hours, and 30 minutes:
P3DT10H30M
The following form indicates a duration of negative 120 days:
-P120D

An optional preceding minus sign (-) indicates a negative duration. If the sign is omitted, a positive duration is assumed.

Reduced precision and truncated representations of this format are allowed, but they must conform to the following requirements:

  • If the number of days, hours, minutes, or seconds in any expression equals zero, the number and its corresponding designator can be omitted. However, at least one number and its designator must be present.
  • The seconds part can have a decimal fraction.
  • The designator T must be absent if and only if all of the time items are absent. The designator P must always be present.
For example, the following forms are allowed:
P13D
PT47H
P3DT2H
-PT35.89S
P4DT251M

The form P-134D is not allowed, but the form -P1347D is allowed.

Db2 database system stores xdt:dayTimeDuration values in a normalized form. In the normalized form, the seconds and minutes components are less than 60, and the hours component is less than 24. Each multiple of 60 seconds is converted to one minute, each multiple of 60 minutes to one hour, and each multiple of 24 hours to one day. For example, the following XQuery expression invokes a constructor function specifying a dayTimeDuration of 63 days, 55 hours, and 81 seconds:

xquery
xdt:dayTimeDuration("P63DT55H81S")

In the duration, 55 hours is converted to 2 days and 7 hours, and 81 seconds is converted to 1 minute and 21 seconds. The expression returns the normalized dayTimeDuration value P65DT7H1M21S.