Blog PHP

datetime value to string in php

This one escapes me everytime I need which results to much googling. The function is to convert SQL datetime value to human-readable format.

*   Converts the likes of '2010-08-01 14:57:15' to 'August 1, 2010, 2:57 pm' 
$datetime_value ="2010-08-01 14:57:15";
echo date(  "F j, Y, g:i a", strtotime( $datetime_value ) );  

Here's another example which you will see on some of my templates.

<?php echo date('Y-m-d', strtotime('next month')); ?>

For more formats, go head to PHP Doc.