From:             eyre dot jonathan at gmail dot com
Operating system: Debian Linux
PHP version:      5.3.16
Package:          Date/time related
Bug Type:         Bug
Bug description:"-1 month" in date moves day 31 to day 1 in the same month.

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 bug report at https://bugs.php.net/bug.php?id=62984&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=62984&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=62984&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=62984&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=62984&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=62984&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=62984&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=62984&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=62984&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=62984&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=62984&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=62984&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=62984&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=62984&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=62984&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=62984&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=62984&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=62984&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=62984&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=62984&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=62984&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=62984&r=mysqlcfg

Reply via email to