470,573 Members | 1,663 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,573 developers. It's quick & easy.

Formatting date returned from MySQL query

Hello,

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

Feb 22 '06 #1
2 1535
la***********@zipmail.com wrote:
Hello,

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

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:
http://us2.php.net/date and most of your questions in general about PHP is at
http://us2.php.net/

--
Michael Austin.
DBA Consultant
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Feb 22 '06 #2
Dave,

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

You want to convert the mysql datetime to a timestamp with strtotime
http://us2.php.net/manual/en/function.strtotime.php and then pass it
into date() with the format you want.

- Clay

Feb 23 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Ben | last post: by
4 posts views Thread by RT | last post: by
5 posts views Thread by Greg | last post: by
Tormod
9 posts views Thread by Tormod | last post: by
3 posts views Thread by =?ISO-8859-2?Q?W=B3adys=B3aw_Bodzek?= | last post: by
1 post views Thread by livre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.