Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting string to timestamp format in MySQL

I have a column in my MySQL database which has timestamp data in string format. I want to convert it into timestamp format.

Below is the sample data:

Date
--------------------------------
Fri Dec 14 14:11:43 IST 2018
Fri Dec 14 14:13:20 IST 2018

I'm expecting the result to be in the following format:

14-12-2018 14:11:43
14-12-2018 14:13:20
like image 811
goonerboi Avatar asked Oct 28 '25 16:10

goonerboi


1 Answers

By using the STR_TO_DATE() to convert the string into a DATETIME, then by using DATE_FORMAT() can change it to the expected date time format.

The following query will return the expected output date time format:

SELECT DATE_FORMAT(
         STR_TO_DATE('Fri Dec 14 14:11:43 IST 2018', '%a %b %d %T IST %Y'), 
       '%d-%m-%Y %H:%i:%s');

Output:

14-12-2018 14:11:43

db<>fiddle demo

Reference formats are available in this link

like image 180
Arulkumar Avatar answered Oct 30 '25 08:10

Arulkumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!