note 29900 deleted from function.strtotime by sniper
| From: | sniper@php.net | Date: | Tue, 21 Oct 2003 11:02:30 +0000 |
| Subject: | note 29900 deleted from function.strtotime by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-59007@lists.php.net to get a copy of this message | ||
Note Submitter: thoane@altern.org
----
Building a log parser for a game called everquest. Dates looks like :
Tue Jul 23 20:13:07 2002
Purpose of this fonction is to convert it to the DATETIME format of MySQL ie :
2002-07-23 20:13:07
function eqstr2date($eqdate)
{
// convert "Tue Jul 23 0:12:56 2002"
// in mysql DATETIME format "2002.2002-07-23 00:12:56";
// short string month date are given a value
$shortmonth = array ("Jan" => 1, "Feb"=>2, "Mar"=>3,
"Apr"=>4, "May"=>5,
"Jun"=>6, "Jul"=>7,"Aug"=>8, "Sep"=>9,
"Oct"=>10, "Nov"=>11, "Dec"=>12);
// parse string $garbage get the rest
list($dayname, $month, $daynum, $garbage) = explode(" ",$eqdate,4);
// parse the rest
list($hour,$minute,$garbage) = explode(":",$garbage,3);
// parse again
list($second,$year) = explode(" ",$garbage,2);
// done !
// mysql DATETIME format :
return date("Y-m-d H:i:s",mktime($hour,$minute,$second,
$shortmonth[$month],$daynum,$year));
}