formatting date field from MYSQL
I am using a DATE field in my MYSQL table, and pulling it through on a php page. The problem is it comes out as "2011-04-23开发者_开发问答"
Is there a way I can reformat this as 23/04/2011?
Thanks :)
date("d/m/Y", strtotime("2011-04-23"));
that should do it
date() strtotime()
DATE_FORMAT(date,format)
Look here: http://dev.mysql.com/doc/refman/5.0/es/date-and-time-functions.html
Assuming variable $date contains your MySQL data:
$date = '2011-04-23';
$timezone = 'Europe/London'; // this is optional argument
$formatted = DateTime::createFromFormat('Y-m-d', $date, new DateTimeZone($timezone));
// or without the optional timezone - where php will assume the default timezone from your OS
$formatted = DateTime::createFromFormat('Y-m-d', $date);
echo $formatted->('d/m/Y');
精彩评论