xs:duration
The primitive type xs:duration
represents a duration of time. It allows you to specify a number of years (Y
), months (M
), days (D
), hours (H
), minutes (M
), and seconds (S
). The lexical representation of xs:duration
is PnYnMnDTnHnMnS
, where an uppercase P
starts the expression, n
indicates the quantity of each component, and an uppercase letter T
separates the day and time components. For example, the value P3YT5H
represents a period of three years and five hours.
The following rules apply to xs:duration
values:
A minus sign may appear at the beginning of the value (before the
P
) to indicate a negative duration.You can omit components whose quantity is zero, but at least one component is required.
If no time components (hours, minutes, seconds) are specified, the
T
cannot appear.The numbers must be integers, except for the number of seconds, which can include a decimal point. XQuery implementations are required to support up to three fractional digits in the number of seconds, but may support more.
If a decimal point appears in the number of seconds, there must be at least one digit after the decimal point.
Table B-9 lists some values of the xs:duration
type. For more information on working with durations, see Chapter 19.
Table B-9. Values of the xs:duration type
Values |
Explanation |
---|---|
Valid | |
P3Y5M8DT9H25M20S |
3 years, 5 months, 8 days, 9 hours, 25 minutes, 20 seconds |
P2DT3H |
2 day, 3 hours |
P25M |
25 months (the number of months may be more than 12) |
PT25M |
25 minutes ... |
Get XQuery now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.