yearMonthDuration data type
The xdt:yearMonthDuration data type represents a duration of time that is expressed by the Gregorian year and month components. Derived from the xs:duration data type.
The lexical form of
xdt:yearMonthDuration is PnYnM, which is a reduced form of the ISO 8601 format. The following abbreviations describe this form:
- nY
- n is an unsigned integer that represents the number of years.
- nM
- n is an unsigned integer that represents the number of months.
An optional preceding minus sign (-) indicates a negative duration. If the sign is omitted, a positive duration is assumed.
P1Y2MThe following form
indicates a duration of negative 13
months:-P13M- The designator
Pmust always be present. - If the number of years or months in any expression equals zero, the number and its corresponding
designator can be omitted. However, at least one number and its designator (
YorM) must be present.
P1347Y
P1347MThe form
P-1347M is not allowed, but the form -P1347M is allowed. The forms
P24YM and PY43M are not allowed because Y must
have at least one preceding digit and M must have one preceding digit.
The Db2 database system stores xdt:yearMonthDuration values in a normalized form. In the normalized form, the months component is less than 12. Each multiple of 12 months is converted to one year. For example, the following XQuery expression invokes a constructor function specifying a yearMonthDuration of 20 years and 30 months:
xquery
xdt:yearMonthDuration("P20Y30M")In the duration, 30 months is converted to 2 years and 6 months. The expression returns the normalized yearMonthDuration value P22Y6M.