note 15819 added to function.mktime
| From: | dave at feltenberger dot net | Date: | Thu, 04 Oct 2001 02:20:48 +0000 |
| Subject: | note 15819 added to function.mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-18547@lists.php.net to get a copy of this message | ||
To format a MySQL date-time variable, use the following function. Pass in the string to format the
date the same as you would with date(), only the second parameter is a MySQL formatted (i.e.
straight from the database, unchanged) date-time variable.
function date_format($format, $mysql_date_time) {
list($date, $time) = explode(" ", $mysql_date_time);
$date_part = explode("-", $date);
$time_part = explode(":", $time);
return date($format,
mktime($time_part[0], $time_part[1], $time_part[2],
$date_part[1], $date_part[2], $date_part[0]));
}
calling the function like this:
print date_format("F j, Y, g:i a", "2001-10-03 20:51:39");
...will result in...
October 3, 2001, 8:51 pm
--
http://www.php.net/manual/en/function.mktime.php
http://master.php.net/manage/user-notes.php?action=edit+15819
http://master.php.net/manage/user-notes.php?action=delete+15819
http://master.php.net/manage/user-notes.php?action=reject+15819