Format date from value in table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Smudly
Forum Commoner
Posts: 71
Joined: Wed Jun 09, 2010 10:09 pm

Format date from value in table

Post 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.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Format date from value in table

Post 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
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Format date from value in table

Post 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;
Post Reply