«

»

May 23 2011

HOWTO: Convert from W3C XML DateTime format to Oracle Timezone

Most XML datetime information is represented like the following:

<date>2011-05-23T12:01:51.217+02:00</date>

So said that, how do you get from that format to a Oracle datetype… The following will help converting you from the W3C datetime towards Oracle datetypes…

WITH datestuff AS
 (SELECT xmltype('<date>2011-05-23T12:01:51.217+02:00</date>') xmlcol 
    FROM dual
 )
SELECT to_timestamp_tz(xt.datum,'YYYY-MM-DD"T"HH24:MI:SS.FF9tzh:tzm') 
       AS "TO_TIMESTAMP_TZ"
FROM   datestuff 
,      xmltable('*'
                passing xmlcol
                COLUMNS
                  datum varchar2(35) PATH '/date'
                ) xt;
 
TO_TIMESTAMP_TZ
-----------------------------------
23-05-11 12:01:51,217000000 +02:00

So use the timestamp with timezone function and make sure the format fits while using a varchar2(35).

1 comment

  1. Marco Gralike

    Alternatively if the origin is a TIMESTAMP column and you need to shred the values via the columns section of XMLTABLE you can use

    DATUM TIMESTAMP(6) WITH TIME ZONE path ‘/date’

    This will result in something like “01-08-11 15:24:04,855000000″

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>