Wednesday, February 23, 2011

How to show date in dd-mmm-yyyy format in php


if you are retrieving date from MySQL table in the format yyyy/mm/dd (e.g. 2005-02-10) and you want to display the date in
converted format like dd-MMM-yyyy (e.g. 10-Feb-2005) in PHP.

Use this code for it ...

Use PHP's date and strtotime:

$output = date('d/M/Y', strtotime($date_from_mysql_Table_Field)) ;

Or use MySQL's built in DATE_FORMAT function:

SELECT DATE_FORMAT(datetime, '%d/%b/%Y') datetime FROM table