To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Newbies

Newbies Help for those who are just getting started

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-07-2009, 09:19 PM   #1
dan90joe
Junior Member
 
Join Date: Nov 2009
Posts: 6
Unhappy PHP Date

This is gonna sound like a complete newbie question, but i have a bunch of fields in a table, one of which is a "date" field.

PHP Code:
$result = mysql_query("SELECT * FROM Guests WHERE Date>=CURDATE() ORDER BY Date LIMIT 6");

while(
$row = mysql_fetch_array($result))
  {

echo
"<table width='720' border='0' align='center'><tr>";
echo
"<td><span class='first'><strong>" . $row['Date'] . "</strong></span></td>";
The page is set to show all row's on or after the current date. This works fine at the moment but i would like to change the format of the date on the output page, as it is currently set to the default of 2009-11-15...

I've searched and searched online and tried a whole bunch of different things for about an hour now and cant seem to make it work. Would like the format of the date to be "15th November 2009" which i think is "jS F Y" according to the PHP manual.

Hopefully somebody can shed some light,

Thanks,
Dan
dan90joe is offline   Reply With Quote
Old 11-07-2009, 09:24 PM   #2
bpat1434
NMaOtBG
 
bpat1434's Avatar
 
Join Date: Oct 2004
Location: Around 255.255.255.0
Posts: 8,093
Use strtotime() with the column value, and use that output of strtotime as the second paramter of date().

PHP Code:
while ($row = mysql_fetch_array($result))
{
    echo
'<td><span class="first"><strong>'.date('jS F Y', strtotime($row['Date'])).'</strong></td>';
}
Hope that helps.
bpat1434 is offline   Reply With Quote
Old 11-07-2009, 09:29 PM   #3
dan90joe
Junior Member
 
Join Date: Nov 2009
Posts: 6
Perfect Thanks - i had come across Strtotime in my searches but didnt know how to include it in my presentation layer...

Thanks!
dan90joe is offline   Reply With Quote
Old 11-07-2009, 09:33 PM   #4
dagon
RTFM it's a way of life.
 
dagon's Avatar
 
Join Date: Nov 2001
Location: N.Z
Posts: 3,088
i prefer to do this kind of thing via mysql DATE_FORMAT function

PHP Code:
$result = mysql_query("SELECT Guests.*, DATE_FORMAT(Date,'%D %M %Y') as Date FROM Guests WHERE Date>=CURDATE() ORDER BY Date LIMIT 6");
dagon is online now   Reply With Quote
Old 11-07-2009, 09:42 PM   #5
dan90joe
Junior Member
 
Join Date: Nov 2009
Posts: 6
Quote:
Originally Posted by dagon View Post
i prefer to do this kind of thing via mysql DATE_FORMAT function

PHP Code:
$result = mysql_query("SELECT Guests.*, DATE_FORMAT(Date,'%D %M %Y') as Date FROM Guests WHERE Date>=CURDATE() ORDER BY Date LIMIT 6");
i tried it your way too, but it messed about with the data that was displayed, didnt show this months details, but instead December's. not sure why...
dan90joe is offline   Reply With Quote
Old 11-07-2009, 09:56 PM   #6
dagon
RTFM it's a way of life.
 
dagon's Avatar
 
Join Date: Nov 2001
Location: N.Z
Posts: 3,088
sorry, as your using Date in the where clause rewriting its format is messing with that, simple solution:

PHP Code:
$result = mysql_query("SELECT Guests.*, DATE_FORMAT(Date,'%D %M %Y') as formatted_date FROM Guests WHERE Date>=CURDATE() ORDER BY Date LIMIT 6");

//then output
$row['formatted_date']
dagon is online now   Reply With Quote
Reply

Bookmarks

Tags
date


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 03:59 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.