smilinmonki666 Posted January 22, 2010 Share Posted January 22, 2010 Hi guys, I would firstly like to apologise that its this subject again. From my research on the web the past 3 days I can see its a big problem & I think it could be my coding as I am learning. My code is as follow & what I am trying to do is return the date to dd/mm/yyyy & not yyyy/mm/dd. Any help is welcome. Thanks in advanced.. <?php $con = mysql_connect("localhost", "admin", "password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database",$con); ?> <? $result = mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT 0,5"); while($row = mysql_fetch_array($result)) { echo "<div id=article>"; echo "<a href=#>" . "<h1>" . $row{'title'} . " - " . "<small>" . $row{'date_add'} . "</a>" . "</small>"; echo "<br>"; echo "<p>" . $row{'intro'} . "<br>" . "<br>" . "<a href=#>" . "<small>" . "Comments" . "</small>" . "</a>" . "</p>"; echo "</div>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/189459-php-mysql-date-formats/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 22, 2010 Share Posted January 22, 2010 You can do it directly in the query - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format No slow parsed, tokenized, interpreted php code is necessary. Quote Link to comment https://forums.phpfreaks.com/topic/189459-php-mysql-date-formats/#findComment-1000068 Share on other sites More sharing options...
hamza Posted January 29, 2010 Share Posted January 29, 2010 $date = $row['date_add'] ; date(' %d / %m / %Y ', strtotime($date) ); will output as expected dd/mm/yy Quote Link to comment https://forums.phpfreaks.com/topic/189459-php-mysql-date-formats/#findComment-1003906 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.