xs:yearMonthDuration

The xs:yearMonthDuration type represents a restriction of the xs:duration type, with only year (Y) and month (M) components allowed. Its lexical representation is PnYnM, where an uppercase P starts the expression, and n indicates the quantity of each component. For example, the value P3Y5M represents a period of three years and five months. You can omit components whose quantity is zero, but at least one component is required.

All of the lexical rules for xs:duration also apply to the xs:yearMonthDuration type. This includes allowing a negative sign at the beginning of the value. Table B-21 lists some values of the xs:yearMonthDuration type.

Important

In previous versions of XQuery (including the Candidate Recommendation), yearMonthDuration was prefixed with xdt: instead of xs: because it was in a different namespace. Some processors still support the previous namespaces for these types instead.

Unlike the xs:duration type, the xs:yearMonthDuration type is totally ordered, meaning that its values can be compared. For more information on working with durations, see Chapter 19.

Table B-21. Values of the xs:yearMonthDuration type

Values

Explanation

Valid

 
P3Y5M

3 years, 5 months

P3Y

3 years

P30M

30 months (the number of months can be more than 12)

P0M

0 months

Invalid

 
P2Y6M3D

Days cannot be specified

P16.6Y

The number of years cannot be expressed as a decimal

P2M1Y

The years must appear before the months

 

An empty value or zero-length string is not permitted

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.47.166