Bug #62984 [Opn->Dup]: "-1 month" in date moves day 31 to day 1 in the same month.
| From: | aharvey@php.net | Date: | Mon, 03 Sep 2012 02:41:50 +0000 |
| Subject: | Bug #62984 [Opn->Dup]: "-1 month" in date moves day 31 to day 1 in the same month. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-173126@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62984&edit=1
ID: 62984
Updated by: aharvey@php.net
Reported by: eyre dot jonathan at gmail dot com
Summary: "-1 month" in date moves day 31 to day 1 in the same
month.
-Status: Open
+Status: Duplicate
Type: Bug
Package: Date/time related
Operating System: Debian Linux
PHP Version: 5.3.16
Block user comment: N
Private report: N
New Comment:
Expected behaviour. Duplicate of bug #22486, bug #44073, bug #62980, and probably about fifty other
bugs in the tracker.
Previous Comments:
------------------------------------------------------------------------
[2012-08-31 16:32:28] eyre dot jonathan at gmail dot com
Description:
------------
When looping backwards in time using the "-1 Month" feature of date(), July is printed
twice. This actually occurs whenever $finalEndDate is a month with 31 days.
The "-1 Month" syntax does not work when the date is the 31st of the month. It apparently
tries to set July 31 to June 31, which does not exist. The 31st of June is calculated to be July
1st, hence the double printing of July 2012 in the example below.
Test script:
---------------
$finalEndDate = "8/31/2012";
$finalStartDate = "12/31/2010";
$StartTime = strtotime($finalStartDate); //$StartDateDB);
$EndTime = strtotime($finalEndDate); //$EndDateDB);
$StartMark = getdate($StartTime);
$EndMark = getdate($EndTime);
$u = 0;
while ($StartTime <= $EndTime) {
$MonthString = $EndMark["month"] . " " . $EndMark["year"];
echo "comparing [" . $StartTime . "] to [" . $EndTime . "]...
created[" . $MonthString . "]<BR>\n";
$u++;
$EndTime = strtotime("-1 month", $EndTime); // THIS IS THE BUGGY LINE
$EndMark = getdate($EndTime);
}
Expected result:
----------------
comparing [1338440400] to [1346389200]... created[August 2012]
comparing [1338440400] to [1343710800]... created[July 2012]
comparing [1338440400] to [1338526800]... created[June 2012]
Actual result:
--------------
comparing [1338440400] to [1346389200]... created[August 2012]
comparing [1338440400] to [1343710800]... created[July 2012]
comparing [1338440400] to [1341118800]... created[July 2012]
comparing [1338440400] to [1338526800]... created[June 2012]
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62984&edit=1