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); ?> Quote Link to comment 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. Quote Link to comment 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.