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
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'];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With