bravo14 0 Posted June 13, 2008 Share Posted June 13, 2008 Hi All I have some dates in a mysql database and it is the format of yyyy-mm-dd and I wanto to display it in a differnet format on the web pages. Any assistance would be much appreciated. Mark Link to post Share on other sites
kmark 0 Posted June 13, 2008 Share Posted June 13, 2008 date("D F j, Y", strtotime($theDate)); would output: Friday Jun 13, 2008 if $thedate = 2008-06-13 Link to post Share on other sites
jesushax 0 Posted June 13, 2008 Share Posted June 13, 2008 heres a function i created <?php function mydate($record){ $date = strtotime($record); echo date('d/m/y',$date); } ?> change the date('d/m/y') to suit the way you want it Link to post Share on other sites
kmark 0 Posted June 13, 2008 Share Posted June 13, 2008 all date formatting option are at http://ca3.php.net/date Link to post Share on other sites
craygo 2 Posted June 13, 2008 Share Posted June 13, 2008 If you want to bypass all the php, why not let mysql do it $sql = "SELECT DATE_FORMAT(`datefield`, '%m/%d/%Y') AS formatted_date"; Ray Link to post Share on other sites
PFMaBiSmAd 131 Posted June 13, 2008 Share Posted June 13, 2008 The mysql DATE_FORMAT() function, as craygo has shown, will result in the fastest execution. The php strtotime() and data() functions are two of the slowest php functions. Link to post Share on other sites
bravo14 0 Posted June 13, 2008 Author Share Posted June 13, 2008 Thanks for your help guys. Craygo just out of curiosity as I am relatively new to PHP/MySQL where in the code below would I put the code you suggested? $result = mysql_query('SELECT * FROM `reports` ORDER by report_id LIMIT 0, 30 ', $con); while($row = mysql_fetch_array($result)) { echo ('<tr class="profiletext"><td>'.$row[date].'</td>'); Link to post Share on other sites
craygo 2 Posted June 16, 2008 Share Posted June 16, 2008 what are the names of the fields in the table?? Link to post Share on other sites
Recommended Posts
Archived
This topic is now archived and is closed to further replies.