Stormdamage February 2016

XQuery transform string into a datetime (exist-db)

I am using XQuery 3.0 for exist-db, and am trying to make the string $value a dateTime object. This is what I've got, but it's not working:

let $value := '"2001-10-18T08:47:00"'

if ($key = 'start_time')
    then 
        element { $key } { xs:dateTime(string(replace($value, '"', ''))) }

It's saying: illegal lexical form for date-time-like value ''. Any ideas?

Answers


joewiz February 2016

I'm unable to reproduce the error you're getting with that code - which is incomplete (lacks return and else clauses, doesn't define $key). But paring those issues away, your code runs fine for me, as follows:

let $value := '"2001-10-18T08:47:00"'
return
    xs:dateTime(replace($value, '"', ''))

The result:

2001-10-18T08:47:00

Post Status

Asked in February 2016
Viewed 1,587 times
Voted 10
Answered 1 times

Search




Leave an answer