Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datetime Display In MySQL

I need your help with datetime coversion. Inside my database I have date of comments entered like this:

  Datetime: 2012-05-08 14:44:53

How can I make it display something close to this

  May 15, 2012 2:44PM

Thanks for your time and patience.


1 Answers

DATE_FORMAT() is the answer to your question. It has several formats of date on this link

SELECT DATE_FORMAT(NOW(), '%M %d, %Y %h:%i %p') as FormattedDate;

View The Output Here [SQLFiddle]

%M  Month name (January..December)
%d  Day of the month, numeric (00..31)
%Y  Year, numeric, four digits
%h  Hour (01..12)
%i  Minutes, numeric (00..59)
%p  AM or PM
like image 56
John Woo Avatar answered Dec 05 '25 20:12

John Woo