note 58682 deleted from function.date by derick
| From: | derick@php.net | Date: | Sun, 11 Jun 2006 11:40:58 +0000 |
| Subject: | note 58682 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114241@lists.php.net to get a copy of this message | ||
Note Submitter: Jay J
----
I use 14 character long datetime fields (20050905105237) in my database. I needed a way to easily
transform them into human-readable format so I wrote the mydate() function.
<?
$datetime = "20050905105237";
$justdate = "20050905";
echo mydate("Y-m-d H:i:s", $datetime);
// Produces 2005-09-05 10:52:37
echo mydate("l, F j, Y", $justdate);
// Produces Monday, September 5, 2005
function mydate($format, $publictime)
{
$sec = substr($publictime, 12, 2);
$min = substr($publictime, 10, 2);
$hour = substr($publictime, 8, 2);
$day = substr($publictime, 6, 2);
$month = substr($publictime, 4, 2);
$year = substr($publictime, 0, 4);
return date($format, mktime($hour, $min, $sec, $month, $day, $year));
}
?>