Blog

Convert a NOW() Value Insert by MySQL in a Different Format with PHP
Posted on June 19, 2015 in MySQL, PHP by Matt Jennings

When doing a MySQL insert statement using NOW() function, a date will be update with a similar format to below:
2015-06-19 19:29:20

To convert this text into something like 7:29pm June 19 2015 use the PHP code below, which is also an snippet that shows how to loop through all rows in a MySQL query:

<?php

// Display MySQL data inserted into the MySQL DB
// from a form on another page
foreach(array_reverse($quotes) as $quote)
{
    echo '<p><span class="big">&ldquo;</span>' . $quote['quote'] . '<span class="big">&rdquo;</span><br /><span class="float-right"> &mdash; ' . $quote['name'] .' at ' . date('g:ia F j Y', strtotime($quote['updated_at'])) . '</span></p>';
}
?>

Leave a Reply