I have $datetime
a value selected from MYSQL datetime column how to convert the format.
this php code doesn't work: <input type="datetime" value=<?php echo '"'.$datetime.'"' ?> />
Input type 'datetime' is HTML5 and only supported in Safari and Opera at this point. It is not going to work for any other browser.
For PHP 5.3 this is very easy:
$date = new DateTime($datetime);
echo $date->format('needful_fromat_here');
You can convert the format in PHP using a combination of strtotime
and date
:
<?php echo '"' . date('d/m/Y', strtotime($datetime)) . '"' ?>
You could also format it in MySQL instead with DATE_FORMAT
DATE_FORMAT(datetimeCol, '%d/%m/%Y')
There are several ways to change the format. First is in the query it self see mysql date time format:
SELECT DATE_FORMAT('2009-10-04 22:23:00', '%W %M %Y');
//'Sunday October 2009'
another option is to do it in PHP
echo date("Y-m-d H:i:s", strtotime($datetime));
// default SQL format, but you get the idea how to change it
// 2012-01-01 10:15:59