Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 803
finst33 Avatar asked Jul 27 '12 23:07

finst33


1 Answers

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'];
like image 142
nickb Avatar answered Sep 30 '22 14:09

nickb