Hey, I am grabbing a date from a row in my table which is currently formatted as:
date("Y-m-d")
2010-09-29
So in my code I have something like this:
$row['date'];
How do I use this to rearrange the date to look like:
09-29-2010
I looked at the formatting tutorials, but they explain how to format it for the date you are currently setting into a variable.
Format date from value in table
Moderator: General Moderators
Re: Format date from value in table
SELECT DATE_FORMAT(`date`, '%m-%d-%Y') AS FormatedDate FROM .....
(See http://dev.mysql.com/doc/refman/5.1/en/ ... ate-format for list)
-Greg
(See http://dev.mysql.com/doc/refman/5.1/en/ ... ate-format for list)
-Greg
Re: Format date from value in table
Also, in case you do not have access to change the SQL, here is how to do it completely with PHP:
Code: Select all
list($year,$month,$day) = explode("-",$row['date']);
echo $month,'-',$day,'-',$year;