Converts $string-var (a string in the yearMonthDuration format) to the yearMonthDuration data type.
If $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.
xf:yearMonthDuration(xs:string $string-var) —> xf:yearMonthDuration
Returns a duration of time as a yearMonthDuration value.
Invoking yearMonthDuration("P1Y2M") returns a yearMonthDuration value corresponding to 1 year and 2 months, as shown in the following example query:
let $mydur := xf:yearMonthDuration("P1Y2M")
return
<components>
<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>
<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>
</components>
The preceding query, generates the following XML result:
<components> <years>1</years> <months>2</months> </components>
Invoking yearMonthDuration("P9Y") returns a yearMonthDuration value corresponding to 9 years, as shown in the following example query:
let $mydur := xf:yearMonthDuration("P9Y")
return
<components>
<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>
<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>
</components>
The preceding query, generates the following XML result:
<components> <years>9</years> <months>0</months> </components>
Invoking yearMonthDuration("-P10M") returns a yearMonthDuration value corresponding to a negative 10 months, as shown in the following example query:
let $mydur := xf:yearMonthDuration("-P10M")
return
<components>
<years>{xf:get-years-from-yearMonthDuration($mydur)}</years>
<months>{xf:get-months-from-yearMonthDuration($mydur)}</months>
</components>
The preceding query, generates the following XML result:
<components> <years>0</years> <months>-10</months> </components>
W3C yearMonthDuration data type description.