Formatting date returned from MySQL query

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Using PHP 4, MySQL 4, I am getting a date field

                $dbh = executeSQL($query);
                while ($row = mysql_fetch_array($dbh)) {
                        $offer_id = $row['offer_id'];
                        $dep_date = $row['depart_day'];
                        // print out date
                        print $dep_date;

THe problem is the date prints out in this form "2006-02-05 00:00:00"
and I want it to print out like this "02/22/2006".

How can I do this?  I would prefer to use a PHP function as opposed to
applying some MySQL date function prior to extracting the result.

Thanks, - Dave

Re: Formatting date returned from MySQL query wrote:

Quoted text here. Click to load it

I am just curious as to why newbies (and some experienced folks as well) ask  
questions here that can readily be found 1) using google and 2) using the  
documentation that has been developed for PHP and MySQL and not have to wait an  
hour or more before someone replies...

Dave the answers to ALL of your "date" questions can be found at: and most of your questions in general about PHP is at

Michael Austin.
DBA Consultant
Donations welcomed. Http://

Re: Formatting date returned from MySQL query


$timestamp = strtotime($row['depart_day']);
$dep_date = date("m/d/Y",$timestamp);

You want to convert the mysql datetime to a timestamp with strtotime and then pass it
into date() with the format you want.  

- Clay

Site Timeline