finst33
finst33

Reputation: 141

Date_format - php

When I try to format the date of a datetime field in my mysql db, and echos' the result, like this:

echo $result["date"];

but yet it says for example, 2012-01-03 10:27:53
my script looks like this:

DATE_FORMAT(date, '%a, %b, &Y')

and it should then say 01, 03, 2012 (or something like this)
is it wrong "type" of echo code i use, i am new to the whole date_format thing so i dont really know if im doing it right.
whole query:

SELECT id, subject, DATE_FORMAT(date, '%a, %b, %Y') FROM articles ORDER BY id DESC

Upvotes: 5

Views: 797

Answers (1)

nickb
nickb

Reputation: 59699

No, you're selecting the original date column value, not the value from DATE_FORMAT().

You need to alias that value like this in your SQL query:

DATE_FORMAT(date, '%a, %b, &Y') as formatted_date

And then pick it up in PHP with:

echo $row['formatted_date'];

Upvotes: 5

Related Questions