Home Ask Login Register

Developers Planet

Your answer is one click away!

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')
        element { $key } { xs:dateTime(string(replace($value, '"', ''))) }

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


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"'
    xs:dateTime(replace($value, '"', ''))

The result:


Post Status

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


Leave an answer

Quote of the day: live life