Category Covered

How to change date format of database output in php

MySQL stores the date in any database (by default) as 'YYYY-MM-DD' .To change date format in any type you can use DATE_FORMAT function in your sql query.

As for example:
$mytest  = “SELECT  yearday as selected_date from balm_yearday   where DATE_FORMAT(yearday,"%d-%m-%y") '';
echo $mytest;
output : 20-01-2015.

Here you can give any type date format such as d/m/y or d-m-y or anything else.
You can also use the strtotime() function to transform your date type as timestamp. Example Code:
$test = $date['selected_date'];
$date1 = strtotime ( $test );
 $mytest=date("d-M-Y", $date1);
echo $mytest;
output : 20-Jan-2015.