Converts $string-var (a string in the time format) to the time 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.
If the value of $string-var is not valid to the time format the following error is reported:
Could not cast "invalid_time_string" to type [time@htttp://www.w3.org/2001/XMLSchema] is displayed.
Where invalid_time_string is the string not valid to the time format, for example: "23:5:44".
xs:time(xs:string $string-var) —> xs:time
Returns the specified time in the time data type.
Invoking time("23:15:45") returns a time value corresponding to 11:15 PM and 45 seconds in the current time zone, as shown in the following example query:
let $mytime := xs:time("23:15:45")
return
<components>
<hours>{xf:get-hours-from-time($mytime)}</hours>
<minutes>{xf:get-minutes-from-time($mytime)}</minutes>
<seconds>{xf:get-seconds-from-time($mytime)}</seconds>
</components>
The preceding query, generates the following XML result:
<components> <hours>23</hours> <minutes>15</minutes> <seconds>45</seconds> </components>
Invoking time("23:15:45Z") returns a time value corresponding to 11:15 PM and 45 seconds in the UTC time zone, as shown in the following example query:
let $mytime := xs:time("23:15:45Z")
return
<components>
<hours>{xf:get-hours-from-time($mytime)}</hours>
<minutes>{xf:get-minutes-from-time($mytime)}</minutes>
<seconds>{xf:get-seconds-from-time($mytime)}</seconds>
</components>
The preceding query, generates the following XML result:
<components> <hours>23</hours> <minutes>15</minutes> <seconds>45</seconds> </components>
Invoking time("23:5:44") outputs an error because the minutes is not specified using two digits.
For example, the following example query:
<result>{xs:time("23:5:44")}</result>
Produces the following error:
Error occurred while executing XQuery: Could not cast "23:5:44" to type [time@http://www.w3.org/2001/XMLSchema]
W3C time data type description