note 100632 added to function.strtotime
| From: | marcodemaio at vanylla dot it | Date: | Wed, 27 Oct 2010 18:09:50 +0000 |
| Subject: | note 100632 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173512@lists.php.net to get a copy of this message | ||
NOTE: strttotime returns wrong values (or guessed values) when the Week day does not macth the date.
Simple example:
<?php
$d1 = strtotime("26 Oct 0010 12:00:00 +0100");
$d2 = strtotime("Tue, 26 Oct 0010 12:00:00 +0100");
$d3 = strtotime("Sun, 26 Oct 0010 12:00:00 +0100"); //But Oct 26 is a Tuesday, NOT a
Sunday.
echo $d1; //ok 1288090800 that is "26 Ott 2010 - 11:00";
echo $d2; //ok 1288090800 that is "26 Ott 2010 - 11:00";
echo $d3; //WRONG! 1288522800 that is "31 Ott 2010 - 11:00";
?>
Sometime I found RSS feeds that contains week days that do not match the date.
A possible solution is to remove useless week day before passing the date string into strtime,
example:
<?php
$date_string = "Sun, 26 Oct 0010 12:00:00 +0100";
if( ($comma_pos = strpos($date_string, ',')) !== FALSE )
$date_string = substr($date_string, $comma_pos + 1);
$d3 = strtotime($date_string);
?>
----
Server IP: 81.88.49.35
Probable Submitter: 151.16.85.158
----
Manual Page -- http://www.php.net/manual/en/function.strtotime.php
Edit -- https://master.php.net/note/edit/100632
Del: integrated -- https://master.php.net/note/delete/100632/integrated
Del: useless -- https://master.php.net/note/delete/100632/useless
Del: bad code -- https://master.php.net/note/delete/100632/bad+code
Del: spam -- https://master.php.net/note/delete/100632/spam
Del: non-english -- https://master.php.net/note/delete/100632/non-english
Del: in docs -- https://master.php.net/note/delete/100632/in+docs
Del: other reasons-- https://master.php.net/note/delete/100632
Reject -- https://master.php.net/note/reject/100632
Search -- https://master.php.net/manage/user-notes.php