PHP Date formatting - MySQL

Associate
Joined
24 Sep 2005
Posts
209
I'd appreciate any help with this problem as although I've been trawling tutorials online etc I still can't get my head around the date formatting concept when displaying data from MySQL in PHP.

Code is as follows:

$events = @mysql_query('SELECT StartDate, EndDate, EventTitle FROM events WHERE StartDate >= NOW()');

while ($event = mysql_fetch_array($events))
{
$startdate = $event['StartDate'];

echo $startdate;

}


Now when I read some tutorials it suggested putting in DATE_FORMAT before the StartDate field in the MySQL select query, but this is not working for me when using the following code:

$events = @mysql_query('SELECT DATE_FORMAT(StartDate, '%d'), EndDate, EventTitle FROM events WHERE StartDate >= NOW()');

It is not displaying any results now. I changed the types of quotation marks around the SQL query incase that made a different but to no joy.


Any assistance would be appreciated! Basically I just want it to display 20th instead of 2008-06-20 etc.

Thanks
 
Thanks for your message Jonny_No2 - I have looked at that manual but still cannot make any sense out of it.

Is there any chance you could give me a brief example of code to explain?

Thanks very much
 
Thats great thanks guys - decided to go with the PHP formatting of the date using strtotime.

Thanks again

Edit: Any ideas how I can do the reverse? i.e when putting a value (e.g. 24th August 2008) into a MySQL database format (2008-08-24?)
 
Back
Top Bottom