|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2012-09-03 02:41 UTC] aharvey@php.net
[2012-09-03 02:41 UTC] aharvey@php.net
-Status: Open
+Status: Duplicate
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 13:00:01 2025 UTC |
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]