note 100632 modified in function.strtotime by derick

From: Date: Sun, 14 Dec 2014 11:25:11 +0000
Subject: note 100632 modified in function.strtotime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-201152@lists.php.net to get a copy of this message
NOTE: strtotime returns different values when the Week day does not match 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 strtotime, 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); ?> --was-- 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); ?> http://php.net/manual/en/function.strtotime.php

« previous php.notes (#201152) next »