473,763 Members | 8,980 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Formatting date returned from MySQL query

Hello,

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

$dbh = executeSQL($que ry);
while ($row = mysql_fetch_arr ay($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 1673
la***********@z ipmail.com wrote:
Hello,

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

$dbh = executeSQL($que ry);
while ($row = mysql_fetch_arr ay($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",$timestam p);

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
32426
by: Ben | last post by:
I would like to use php to query a database and retrieve a unix timestamp. The problem is that mysql is storing the data in the date format and not a timestamp. I am sure that I can amend my query to format the date returned as a timestamp without having to do the conversion in php. Can someone tell me what to put in my db query?
4
1983
by: Slant | last post by:
I have been using MySQL in conjunction with PHP for many years now... I have been using the exact same method for not only connecting to a database and performing the queries but also displaying the results. I've been told numerous times that my methods are out-dated. I'm more than willing to cede to this possibility but I need help getting out of the rut!!! Can anyone help me? Here are some examples:
4
7082
by: RT | last post by:
If anyone can help that would be great. I¹m trying to format a timestamp from my MySQL table (sessions) Here¹s the code I¹m using: <?php echo date('D,n-j-y h:i:s a',strtotime($row_rsSessions)); ?> If I give the timestamp a value of 8 I can get the date to work correctly
5
2284
by: Greg | last post by:
I have a page that searches a database by a repairman's name and by a date range. It pulls info by the repairman's name but pulls all info in the database regardless of the date. Below is the code of the two pages. What am I missing? This page calls the script datersearch.php ************ searchrdates.php ************
2
1190
by: Sara | last post by:
The problem: Conditional formatting bold, red when field Value < date() sets the field background to white - always - whether condition is met or not. I want the field unfilled and just red/bold when the date has passed. Background: I have 2 related fields that are only rarely active, so I manage them in the query for the subform: ShowBlanket: IIf(,"Blanket","") and
9
2123
Tormod
by: Tormod | last post by:
I'm having problems formatting a date retrieved from mysql database. When I retrieve the date it's in the format YYYY-MM-DD. I need to split the Day, Month and Year portions of the date up so that I can represent them in a drop down menu. I've posted my source code below, such as it is. I need a function of some kind to allow me to manipulate the $row. #connect to mysql $conn = @mysql_connect( "host", "username", "password" )...
3
1303
by: shmoopie | last post by:
Hi, I have a php form that I want to use to pass a user specified "start date" and "end date" to a mysql database to retrieve reservations. I want the number of days up to and including the "end date" to be displayed for both of these scenarios: 1) The item is still on loan as of the "end date" 2) The item has already been returned as of the "end date" Right now I have it working by specifying a "start date", but the "end date" is...
7
3507
hodgeman
by: hodgeman | last post by:
Hello thescripts forums users... I've found a lot of answers to problems I've had in the past from this forum, and this is the first mySQL query issue I haven't been able to find an answer from anywhere so thought my time first post should be here. With that out the way... I have a website I've built for my day job rotoruaNZ.com/events that I'd like to improve upon. We have numerous events posted on our website that take place around...
3
6697
by: =?ISO-8859-2?Q?W=B3adys=B3aw_Bodzek?= | last post by:
Hi, I want to change 2 default behaviors of ms-sql server within a connection. 1. All varchar (etc.) fields should be returned as UTF-8. I know about field attribute collation and convert function, but I want simple query like: SELECT * FROM table; to return all varchars as UTF-8, no matter how the fields were defined and which collation.
0
9564
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10002
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.