Search code examples
datetimexquery

Convert "2020-09-14T14:04:43.123+0000" to Datetime in format "YYYY-MM-DD HH24:MI:SS" and add minutes in XQuery


How convert "2020-09-14T14:04:43.123+0000" to Datetime "YYYY-MM-DD HH24:MI:SS" and add minutes in XQuery.


Solution

  • To convert the used dateTime format to the one the xs:dateTime constructor functions expects you could insert a colon:

    xs:dateTime("2020-09-14T14:04:43.123+0000" => replace('([0-9)][0-9])([0-9][0-9])$', '$1:$2'))
    

    To add some minutes add an xs:dayTimeDuration with the right M (minutes) component e.g.

    xs:dateTime("2020-09-14T14:04:43.123+0000" => replace('([0-9)][0-9])([0-9][0-9])$', '$1:$2')) + xs:dayTimeDuration('PT12M')
    

    To format construct the right picture string for format-dateTime e.g.:

    format-dateTime(xs:dateTime("2020-09-14T14:04:43.123+0000" => replace('([0-9)][0-9])([0-9][0-9])$', '$1:$2')) + xs:dayTimeDuration('PT12M'), '[Y0001]-[M01]-[D01] [H01]24:[m01]:[s01]')