Functions are great because they are reusable so I decided since I use different date/time formats why not pass the date and format as parameters?
The function simply returns the value (you'll have to echo the function where you need it). You call the function with two variables: the first being the MySQL NOW() formatted date/time and the second the format for the time stamp.
To construct a time stamp to change date and time formatting (in example between 12, Dec, and December) simply use http://php.net/date as a reference guide.
Suggestions for improvement are welcome. I adapted this from rana_0036's php.net comment at http://php.net/time.
Code: Select all
function date_mysql($date, $format)
{
$d = explode("-", $date);
$time = explode(" ", $d[2]);
$t = explode(":", $time[1]);
$datetime_converted = date($format, mktime ($t[0],$t[1],$t[2],$d[1],$d[2],$d[0]));
return $datetime_converted;
}
echo date_mysql("2008-11-03 14:53:12", "l F jS, Y, h:i A");
//Output: Monday November 3rd, 2008, 02:53 PM