I need to convert a date from this format:
2002-10-10T12:00:00-05:00
(xs:dateTime as defined in XML)
to an Oracle date.
I’m used to using this in PL/SQL: to_date(‘date here’, ‘yyyymmdd’), is there a way to convert this while keeping the time zone info?
Thanks
Oracle dates don’t have timezone information. You’ll need to use a TIMESTAMP datatype instead.
It works something like this:
Note, there is the tricky issue of the T in the XSD notation. That hurls a
ORA-01858exception, because it’s not a valid format in Oracle. I’m sure there is a workaround, but it currently escapes me.Well, one workaround is to apply SUBSTR() function sto split open the two parts of the timestamp, as Bob shows. But there ought to be a more elegant way.
It probably doesn’t qualify as “elegant” but as it’s a string we can use a substitution function to get rid of the annoying T:
But given all the effort Oracle have put into XMLDB it is rather annoying that there isn’t a tidier solution.
In my original sample I use a format mask of
'YYYY-MM-DD HH24:MI:SS-TZH:TZM'. This interprets the-in the time zone as a separator not a minus sign. Consequently it returned +05:00. I have since corrected my code sample to remove that last dash. Now the timezone is correctly rendered as -05:00. Sorry for any confusion.