Page 1 of 1

Format date from value in table

Posted: Wed Sep 29, 2010 11:37 am
by Smudly
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.

Re: Format date from value in table

Posted: Wed Sep 29, 2010 12:14 pm
by twinedev
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

Re: Format date from value in table

Posted: Wed Sep 29, 2010 12:17 pm
by twinedev
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;