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. Link to comment https://forums.phpfreaks.com/topic/78599-solved-changing-date-format-when-called-from-mysql-dbase/ Share on other sites More sharing options...
BenInBlack Posted November 23, 2007 Share Posted November 23, 2007 date('m-d-Y',strtotime($row['Date'])); Link to comment https://forums.phpfreaks.com/topic/78599-solved-changing-date-format-when-called-from-mysql-dbase/#findComment-397706 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> Link to comment https://forums.phpfreaks.com/topic/78599-solved-changing-date-format-when-called-from-mysql-dbase/#findComment-397718 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 Link to comment https://forums.phpfreaks.com/topic/78599-solved-changing-date-format-when-called-from-mysql-dbase/#findComment-397719 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> Link to comment https://forums.phpfreaks.com/topic/78599-solved-changing-date-format-when-called-from-mysql-dbase/#findComment-397720 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> Link to comment https://forums.phpfreaks.com/topic/78599-solved-changing-date-format-when-called-from-mysql-dbase/#findComment-397727 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 Link to comment https://forums.phpfreaks.com/topic/78599-solved-changing-date-format-when-called-from-mysql-dbase/#findComment-397740 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.