note 58682 added to function.date
| From: | JayJ at osu1 dot php dot net | Date: | Fri, 11 Nov 2005 17:13:30 +0000 |
| Subject: | note 58682 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-98438@lists.php.net to get a copy of this message | ||
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));
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+58682
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58682&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58682&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58682&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58682&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58682&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58682&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58682&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+58682&report=yes
Search -- http://master.php.net/manage/user-notes.php