Jb. Jb. - 5 months ago 20
MySQL Question

How to convert from datetime format in mysql databse into normal am/pm format?

I am using MySQL for my database and working with Spring.

For export functionality, I am generating a report(excel sheet). In that I have a field called "Created On". I am putting the data i get from database into that field which is in DATETIME format.

like this:
'2016-05-22 17:06:55'

But what I would like to have in my report need to be like this: '05-22-2016 05:06:55 PM'

Thanks in advance.

Answer

Use date_format;

select date_format('2016-05-22 17:06:55', '%m-%d-%Y %h:%i:%s %p')

SQLFiddle DEMO HERE