I have to perform some inserts into an Oracle DB. I have some dates in the following format
'23.12.2011 13:01:001'
Following the documentation I wrote inserts to_date as follows:
to_date('23.12.2011 13:01:01', 'DD.MM.YYYY HH24:MI:SS')
which works properly. Now I have dates with milliseconds with the format
'23.12.2011 13:01:001'
I've tried the following:
to_date('23.12.2011 13:01:001', 'DD.MM.YYYY HH24:MI:SSFF3')
which is incorrect (delivers an error 01821. 00000 - "date format not recognized").
Which "String" should I use for this format with milliseconds?
Thanks in advance!
To_char formats a DATE into a string using the given format mask. To_date converts a STRING into a date using the format mask.
TO_DATE converts char of CHAR , VARCHAR2 , NCHAR , or NVARCHAR2 datatype to a value of DATE datatype. The fmt is a datetime model format specifying the format of char . If you omit fmt , then char must be in the default date format. If fmt is J , for Julian, then char must be an integer.
Oracle to_char date format milliseconds Milliseconds is microseconds divided by 1000 ( milliseconds = microseconds / 1000 ). And 1 second has 1000 milliseconds. Oracle date data types do not support milliseconds but Oracle timestamps do.
SELECT TO_CHAR ( TO_DATE (date_value, 'yyyy-mm-dd') , 'mm/dd/yyyy' ) FROM table_x; Thank you,!!!! That did the trick.
An Oracle DATE
does not store times with more precision than a second. You cannot store millisecond precision data in a DATE
column.
Your two options are to either truncate the string of the milliseconds before converting it into a DATE
, i.e.
to_date( substr('23.12.2011 13:01:001', 1, 19), 'DD.MM.YYYY HH24:MI:SS' )
or to convert the string into a TIMESTAMP
that does support millisecond precision
to_timestamp( '23.12.2011 13:01:001', 'DD.MM.YYYY HH24:MI:SSFF3' )
TO_DATE supports conversion to DATE datatype, which doesn't support milliseconds. If you want millisecond support in Oracle, you should look at TIMESTAMP datatype and TO_TIMESTAMP function.
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With