note 90213 added to function.date-parse-from-format
| From: | voidless at qip dot ru | Date: | Fri, 10 Apr 2009 12:56:58 +0000 |
| Subject: | note 90213 added to function.date-parse-from-format | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153047@lists.php.net to get a copy of this message | ||
Example of rewriting function for older PHP versions:
convert
April 8, 2009, 1:12 am
to
timestamp
<?php
function date2sql($str = ""){
$month_arr = array (
"January" => 1,
"February" => 2,
"March" => 3,
"April" => 4,
"May" => 5,
"June" => 6,
"July" => 7,
"August" => 8,
"September" => 9,
"October" => 10,
"November" => 11,
"December" => 12
);
preg_match('/([a-zA-Z]{3,9}) ([0-9]{1,2}), ([0-9]{4}),
([0-9]{1,2}):([0-9]{1,2}) ([ap])m/',$str,$matches2);
if ($matches2[6]=="a") $hour = $matches2[4];
else $hour = $matches2[4]+12;
if ($hour==24) $hour=0;
return mktime($hour,$matches2[5],0,
$month_arr[$matches2[1]],$matches2[2],$matches2[3]);
}
$time = date2sql("March 29, 2009, 12:12 pm");
echo "{$time}</br>\n";
?>
----
Server IP: 78.41.111.3
Probable Submitter: 195.131.219.216
----
Manual Page -- http://www.php.net/manual/en/function.date-parse-from-format.php
Edit -- https://master.php.net/note/edit/90213
Del: integrated -- https://master.php.net/note/delete/90213/integrated
Del: useless -- https://master.php.net/note/delete/90213/useless
Del: bad code -- https://master.php.net/note/delete/90213/bad+code
Del: spam -- https://master.php.net/note/delete/90213/spam
Del: non-english -- https://master.php.net/note/delete/90213/non-english
Del: in docs -- https://master.php.net/note/delete/90213/in+docs
Del: other reasons-- https://master.php.net/note/delete/90213
Reject -- https://master.php.net/note/reject/90213
Search -- https://master.php.net/manage/user-notes.php