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 in "Dividing Durations by Durations," later in this chapter.
Table 19-6 shows some examples of calls to the component extraction functions.
Table 19-6. Examples of the component extraction functions
Example |
Return value |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
If you want to extract the entire date or time from an xs:dateTime
value, you can cast that value to the desired type (either xs:date
or xs:time
).
3.145.109.8