Siggles Posted November 23, 2007 Share Posted November 23, 2007 Hi, I have a script that puts a date into a mysql dbase in the 2001-10-01 format. I want it to display in the 01-10-2001 format. My reasoning for using the 'date' type in the dbase is that later on in my website I want to put some dates (for gigs) into date order. That all works fine. However, when outputting the dates using the $row['Date'] it obviously outputs it in the wrong format. I have seen the php functions that change date format but because of the way I output the rows of the mysql dbase I have problems iimplementing them. See below... $result = mysql_query("SELECT * FROM Gigs ORDER BY Date"); while($row = mysql_fetch_array($result)) { echo "<table width=\"100%\" >"; echo "<tr > <td><span class=\"style55\">".$row['Date']."</span></td> </tr>"; } Can anyone help. I can explain my script more if it helps. Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted November 23, 2007 Share Posted November 23, 2007 date('m-d-Y',strtotime($row['Date'])); Quote Link to comment Share on other sites More sharing options...
Siggles Posted November 23, 2007 Author Share Posted November 23, 2007 date('m-d-Y',strtotime($row['Date'])); Wont the ; stop the while loop? Do I put the whole thing in between... <td><span class=\"style55\">"date('m-d-Y',strtotime($row['Date']));"</span></td> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 23, 2007 Share Posted November 23, 2007 You can use the mysql date_format() function directly in your SELECT query, that is what it was designed for - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html Quote Link to comment Share on other sites More sharing options...
revraz Posted November 23, 2007 Share Posted November 23, 2007 Remove the ; from the part above, since you aready have it after your </td> Quote Link to comment Share on other sites More sharing options...
Siggles Posted November 23, 2007 Author Share Posted November 23, 2007 Remove the ; from the part above, since you aready have it after your </td> Your advice worked a treat. This is how the script looks for anyone interested. Thak you very much. <span class=\"style55\">".date('d-m-Y',strtotime($row['Date']))."</span> Quote Link to comment Share on other sites More sharing options...
Siggles Posted November 23, 2007 Author Share Posted November 23, 2007 Actually now it looks like this.... <td><span class=\"style55\">".date('l jS F Y',strtotime($row['Date']))."</span></td> or Saturday 1st December 2007 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.