Jump to content

Convert date from a database query


hazniet

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.