General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old November 9th, 2002, 03:02 AM
anderpants anderpants is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: England
Posts: 10 anderpants User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 32 sec
Reputation Power: 0
Format Date from query

Help!
Have a mySQL query complete with INNER JOIN. One of the results is in the form of a date, and i want to display that date as MM,DD,YY. Now i can do that on a simple query getting one record containing the date using date_format(lastFlown, '%M %e, %Y') etc. But can't reproduce it on a large query such as below:
-----------------------------------------------------------------------------------
$query_rsAircraftFlown = sprintf("SELECT personal.idno, personal.email, aircraftFlown.recognId,
aircraftFlown.aircraftType, aircraftFlown.hoursP1, aircraftFlown.idno, aircraftFlown.hoursP2,
aircraftFlown.lastFlown, aircraftFlown.trainingPosition
FROM personal INNER JOIN aircraftFlown ON personal.idno = aircraftFlown.recognId WHERE email = '%s'", $colname_rsAircraftFlown);
------------------------------------------------------------------------------------
lastFlown is the date i am trying to format.
Can anyone help me.
Many thanks

Reply With Quote
  #2  
Old November 9th, 2002, 07:59 AM
wAr-AnGeL wAr-AnGeL is offline
Forum Security
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Behind You
Posts: 479 wAr-AnGeL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m
Reputation Power: 7
Send a message via ICQ to wAr-AnGeL Send a message via AIM to wAr-AnGeL
is lastFlown an Unix timestamp?

if so:
PHP Code:
 $formattedDate date("n,d,y""$lastFlown");
echo 
$formattedDate


hope it helps
__________________




"Only Linux users see the end of crashes."
- Pl4t0

Reply With Quote
  #3  
Old November 10th, 2002, 12:35 AM
anderpants anderpants is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: England
Posts: 10 anderpants User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 32 sec
Reputation Power: 0
War Angel,
thanks for your help.
The table column just holds an inputted date as yyyy-mm-dd. I tried your code as below:


$lastflown = $row_rsAircraftFlown['lastFlown'];
$formatLastFlown = date("m,d,Y", "$lastflown");

but the result is 01,01,1970 (previously 1982-05-29 00:00:00 and i would like it to display 05-29-1982). Is there any way of doing this in the sql query?

regards

Reply With Quote
  #4  
Old November 10th, 2002, 12:48 AM
wAr-AnGeL wAr-AnGeL is offline
Forum Security
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Behind You
Posts: 479 wAr-AnGeL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m
Reputation Power: 7
Send a message via ICQ to wAr-AnGeL Send a message via AIM to wAr-AnGeL
how is lastFlown determined?

date() can only format unix timestamps. so when you insert lastFlown you would insert the current time by doing

$lastFlown = time();
insert into db....

then you can format it with the date() code I gave you when you Select it from the db.

Reply With Quote
  #5  
Old November 10th, 2002, 12:52 AM
anderpants anderpants is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: England
Posts: 10 anderpants User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 32 sec
Reputation Power: 0
lastFlown is inserted into the database via a form.

Reply With Quote
  #6  
Old November 10th, 2002, 02:38 AM
wAr-AnGeL wAr-AnGeL is offline
Forum Security
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Behind You
Posts: 479 wAr-AnGeL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m
Reputation Power: 7
Send a message via ICQ to wAr-AnGeL Send a message via AIM to wAr-AnGeL
so when the person submits the form that moment in time is lastFlown?

Reply With Quote
  #7  
Old November 10th, 2002, 02:45 AM
anderpants anderpants is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: England
Posts: 10 anderpants User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 32 sec
Reputation Power: 0
no, its a date they can enter themselves

Reply With Quote
  #8  
Old November 10th, 2002, 02:04 PM
littleblackdog littleblackdog is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Anchorage
Posts: 118 littleblackdog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
I would just..

I would just output what they input, not changing, since they could input anything.

Depending on what your reason for the date, you may want the computer or server to assign the date for you... can bring up other issues, like the different time zones, etc.

I'm still just learning php, but I've used time() before for a guest book and had to format it for different time zones, it worked well. But if the user inputs the date, you may have trouble, unless they ALL do it the same way each time.
__________________
bow wow!

Reply With Quote
  #9  
Old November 10th, 2002, 04:30 PM
wAr-AnGeL wAr-AnGeL is offline
Forum Security
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Behind You
Posts: 479 wAr-AnGeL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m
Reputation Power: 7
Send a message via ICQ to wAr-AnGeL Send a message via AIM to wAr-AnGeL
if its user inputted the only way i can think of is making lastFlown varchar and having them input the date like 11/11/02 and output it without any formatting.

Reply With Quote
  #10  
Old November 11th, 2002, 03:36 AM
anderpants anderpants is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: England
Posts: 10 anderpants User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 32 sec
Reputation Power: 0
I need the date to be searchable, and to make it user friendly for the user, i used three drop down lists (day,month,year) and then run this:
-----------------------------------------------------------------
$dash = "-";
$lastFlown = $lastFlownYear.$dash.$lastFlownMonth.$dash.$lastFl ownDay;
-----------------------------------------------------------------
and then inputted $lastFlown into the database formatted for mySQL.

I have managed a work around to display the date as I required although there is probably a much cleaner way of doing it:
-----------------------------------------------------------------
//format last flown
$lastFlown = substr_replace($row_rsaircraftFlown['lastFlown'], '',11,8);
//split last Flown into pieces
$lastFlown = explode("-", $lastFlown );
$trimlastFlown = trim($astFlown [2]);
$lastFlown = "$trimlastFlown-$lastFlown [1]-$dateOB[0]";
-----------------------------------------------------------------

the //format last Flown removes the 00:00:00 from the end.
the final prodcut is mm/dd/yyyy

As i said, probably not very efficient but it works!
Many thanks for your help.
regards,

Reply With Quote
  #11  
Old November 11th, 2002, 08:53 AM
ChiMex ChiMex is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: Colorado
Posts: 22 ChiMex User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
You may want to try something like this to format your dates from the db.

PHP Code:
/*Convert date to a time stamp.
Convert to desired formatted date.*/
$date_string strtotime($date_from_db);
$date_formated date("F d, Y"$date_string); 


You can replace the F d, Y to whatever format you want.

Hope that helps.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Format Date from query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway