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;

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.

you can use strtotime to convert your existing date to a time stamp. You can then use that time stamp in a date command to create whatever format you need.

I ended up using this.

Thanks

$date = $row;
$dArray = explode("-", $date);
$newDate = $dArray[1]. "-" .$dArray[2] ."-". $dArray[0];

Hi Smudly,

I format the date in the query because it allows for a few more options.
e.g:

SELECT *, DATE_FORMAT(Date, '%a, %e %M, %y') as newDate FROM `db`

And then just output like so:

echo "<td>".$row['newDate']."</td>";

This code outputs the date as such: Sun, 7th January, 10

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.