xs:dayTimeDuration

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

The range that can be represented by this data type is from -P11574074073DT23H163M219.999999999999S to P11574074073DT23H163M219.999999999999S (or -999999999999999.999999999999 seconds to 999999999999999.999999999999 seconds).

The lexical form of xs: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 twelve 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® stores xs: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. DB2 converts each multiple of 60 seconds to one minute, each multiple of 60 minutes to one hour, and each multiple of 24 hours to one day. For example, the following XPath expression invokes a constructor function specifying a dayTimeDuration of 63 days, 55 hours, and 81 seconds:

xs:dayTimeDuration("P63DT55H81S")

DB2 converts 55 hours to 2 days and 7 hours, and 81 seconds to 1 minute and 21 seconds. The expression returns the normalized dayTimeDuration value P65DT7H1M21S.