Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert "1985-02-07T00:00:00.000Z" (ISO8601) to a date value in Oracle?

I tried to convert a time-stamp ("1985-02-07T00:00:00.000Z") to a date and I failed to succeed in my several different attempts.

Below is the query I have tried:

 select to_date('1985-02-07T00:00:00.000Z', 'YYYY-MM-DDTHH24:MI:SS.fffZ')  from dual; 

Your suggestions are greatly appreciated.

like image 390
Abilash Avatar asked Dec 28 '11 09:12

Abilash


People also ask

How do I change date format from YYYY-MM-DD in Oracle?

SELECT TO_CHAR ( TO_DATE (date_value, 'yyyy-mm-dd') , 'mm/dd/yyyy' ) FROM table_x; Thank you,!!!! That did the trick.

What is the format for date in Oracle?

Oracle stores dates in an internal numeric format representing the century, year, month, day, hours, minutes, seconds. The default date format is DD-MON-YY.

Can we convert date to TIMESTAMP in Oracle?

Oracle has expanded on the DATE datatype and has given us the TIMESTAMP datatype which stores all the information that the DATE datatype stores, but also includes fractional seconds. If you want to convert a DATE datatype to a TIMESTAMP datatype format, just use the CAST function.


1 Answers

to_date converts the input to a DATE type which does not support fractional seconds. To use fractional seconds you need to use a TIMESTAMP type which is created when using to_timestamp

pst's comment about the ff3 modifier is also correct.

"Constant" values in the format mask need to be enclosed in double quote

So the final statement is:

select to_timestamp('1985-02-07T00:00:00.000Z', 'YYYY-MM-DD"T"HH24:MI:SS.ff3"Z"') from dual; 
like image 195
a_horse_with_no_name Avatar answered Oct 15 '22 01:10

a_horse_with_no_name