Skip to content
Advertisement

how to convert to_timestamp(’12-10-18 12:00:16.565736000 PM’,’DD-MM-RR HH12:MI:SSXFF AM’) into MySQL

I have one insert query in oracle —

Insert into sample (name,time) values ('RJ-valley',to_timestamp('12-10-18 12:00:16.565736000 PM','DD-MM-RR HH12:MI:SSXFF AM'));

select time from sample;

output : 12-10-18 12:00:16.565736000 PM

same how can i insert in MySQL and i want output as same as oracle.

Advertisement

Answer

First try to convert str_to_date then do a date_format

so the query should be as

SELECT 
    DATE_FORMAT(STR_TO_DATE(@q, '%d-%m-%y %h:%i:%s.%f000 %p'),
            '%d-%m-%y %h:%i:%s.%f000 %p') AS to_date;

Sharing the fiddle here db-fiddle

p.s.

In MySQL the maximum fraction is 6, so as you have shared 9 with last 3 are zero then no issues.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement