Richard
Richard

Reputation: 37

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 :)

Upvotes: 0

Views: 769

Answers (3)

Michael J.V.
Michael J.V.

Reputation: 5609

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');

Upvotes: 0

elvenbyte
elvenbyte

Reputation: 776

DATE_FORMAT(date,format)

Look here: http://dev.mysql.com/doc/refman/5.0/es/date-and-time-functions.html

Upvotes: 1

wired00
wired00

Reputation: 14508

date("d/m/Y", strtotime("2011-04-23"));

that should do it

date() strtotime()

Upvotes: 2

Related Questions