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 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.
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 designatorP
must always be present.
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.