hazniet Posted April 9, 2007 Share Posted April 9, 2007 I have a simple database for events. I have a column named "date" that I would like to display as "March 8, 2007" on the webpage. What do I need to add to change the date format? Here is my php code: $connection = mysql_connect($server, $user, $pass); mysql_select_db($db) or die ("Unable to select database!"); $query = "SELECT * FROM events ORDER by date"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); if (mysql_num_rows($result) > 0) { echo "<h2>2006-2007</h2><table width='100%'>"; while($row = mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td width='33%'>".$row['date']."</td>"; echo "<td width='25%'>".$row['event']."</a></td>"; echo "<td>".$row['location']."</td>"; echo "</tr>"; } echo "</table><hr>"; } else { echo "No rows found!"; } mysql_free_result($result); mysql_close($connection); ?> Link to comment https://forums.phpfreaks.com/topic/46215-convert-date-from-a-database-query/ Share on other sites More sharing options...
btherl Posted April 9, 2007 Share Posted April 9, 2007 You can use strtotime() and date() to achieve that. Both those functions are listed here: http://sg.php.net/manual/en/ref.datetime.php strtotime() will convert the mysql date into a timestamp, and date() can format the timestamp according to your specification. Link to comment https://forums.phpfreaks.com/topic/46215-convert-date-from-a-database-query/#findComment-224711 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.