Converts $string-var (a string in the duration format) to the duration data type.
If the value of $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.
xs:duration(xs:string $string-var) —> xs:duration
Returns a duration of time as a duration value.
Invoking duration("P1Y2M4DT9H8M20S") returns a duration value corresponding to 1 year, 2 months, 4 days, 9 hours, 8 minutes, and 20 seconds, as shown in the following example query:
<result>{xs:duration("P1Y2M4DT9H8M20S")}</result>
The preceding query, generates the following XML result:
<result>P1Y2M4DT9H8M20S</result>
Invoking duration("P9Y") returns a duration value corresponding to 9 years, as shown in the following example query:
<result>{xs:duration("P9Y")}</result>
The preceding query, generates the following XML result:
<result>P9Y</result>
Invoking duration("-P10M") returns a duration value corresponding to negative 10 months as shown in the following example query:
<result>{xs:duration("-P10M")}</result>
The preceding query, generates the following XML result:
<result>-P10M</result>
Invoking duration("P4DT20S") returns a duration value corresponding to 4 days and 20 seconds, as shown in the following example query:
<result>{xs:duration("P4DT20S")}</result>
The preceding query, generates the following XML result:
<result>P4DT20S</result>
W3C duration data type description