Extracting Components of Dates, Times, and Durations
A number of functions allow you to extract specific parts of dates, times, and durations. For example, to retrieve the year part of a date, you can use the year-from-date function. Table 19-5 lists all the component extraction
functions for date, time, and duration values.
Table 19-5. Component extraction functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
When working with duration values, these functions calculate the result based on the canonical representation of the values. For example, the function years-from-duration does not necessarily return the integer that appears before the Y in the original value. Rather, it returns the number of whole years in the duration, taking into account that the number of months might be more than 12. If the xs:duration value is P1Y15M, the function returns 2, not 1. This is because the canonical representation of P1Y15M (1 year and 15 months) is actually P2Y3M (2 years and 3 months). To extract the number of years as a decimal number, you could instead divide the value by the duration P1Y, which would return 2.25. This is described ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access