Nice dates with PHP revisted
Published on Wednesday 20 April 2016. Tagged as PHP.
MySql gives the posted date of the post back in this format: 2016-04-17 20:58:00. To display the date in a more readable format and to display a nice tear-off calender cartouche in lists, I now use the PHP date/time functions instead of string manipulation.
Converting a date/time value from MySql
This is a rework from the previous post Nice dates with PHP. This is the PHP code to render each item of the posts list on the homepage, including the nice date/time format and the tear-off calender cartouche, but now using the PHP native DateTime object. .
$dt=new DateTime( $item['publishdate'] );
echo '<li><a href="'.ROOT.'/post/'.$item['slug'].'">';
tag( 'h2', $item['subject']);
tag( 'p class="info"', 'Published on '.$dt->format('l d F Y').'.' );
tag( 'p', $item['description'] );
I converted this blog system to a more traditional one: rendering dynamic pages from data stored in a MySql database. I wrote this complete basic PHP application from scratch in less than 8 hours. It is still lightning fast. In posts to come, I'll explain in detail what I did.