3

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
P P P
  • 227
  • 3
  • 16
goonerboi
  • 309
  • 6
  • 18

2 Answers2

3

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

Arulkumar
  • 12,966
  • 14
  • 47
  • 68
0

You could use str_to_date()

str_to_date('Fri Dec 14 14:11:43 IST 2018', '%a %b %d %T IST %Y');
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107