bravo14 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 comment https://forums.phpfreaks.com/topic/110068-displaying-dates/ Share on other sites More sharing options...
kmark 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 comment https://forums.phpfreaks.com/topic/110068-displaying-dates/#findComment-564805 Share on other sites More sharing options...
jesushax 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 comment https://forums.phpfreaks.com/topic/110068-displaying-dates/#findComment-564806 Share on other sites More sharing options...
kmark Posted June 13, 2008 Share Posted June 13, 2008 all date formatting option are at http://ca3.php.net/date Link to comment https://forums.phpfreaks.com/topic/110068-displaying-dates/#findComment-564810 Share on other sites More sharing options...
craygo 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 comment https://forums.phpfreaks.com/topic/110068-displaying-dates/#findComment-564817 Share on other sites More sharing options...
PFMaBiSmAd 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 comment https://forums.phpfreaks.com/topic/110068-displaying-dates/#findComment-564939 Share on other sites More sharing options...
bravo14 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 comment https://forums.phpfreaks.com/topic/110068-displaying-dates/#findComment-565225 Share on other sites More sharing options...
craygo Posted June 16, 2008 Share Posted June 16, 2008 what are the names of the fields in the table?? Link to comment https://forums.phpfreaks.com/topic/110068-displaying-dates/#findComment-566460 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.