#39560 [NEW]: Inconsistent behaviour of strtotime when days > days in month

From: Date: Mon, 20 Nov 2006 17:03:48 +0000
Subject: #39560 [NEW]: Inconsistent behaviour of strtotime when days > days in month
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-105207@lists.php.net to get a copy of this message
From: php at colin dot guthr dot ie Operating system: Linux PHP version: 5.2.0 PHP Bug Type: Date/time related Bug description: Inconsistent behaviour of strtotime when days > days in month Description: ------------ If you give a date to strtotime that is beyond the end of a given month it sometimes calculates the date correctly (IMO) as the first day of the next month, but this does not happen in months with 31 days. e.g. strtotime('2006-11-31') will correctly create a date of 2006-12-01, but strtotime('2006-11-32') will not create a date of 2007-01-01 as expected. This is the case for all months that have 30 days (and I presume february too). Putting in 31 as the number will overflow to the next month, but putting in 32 in any month will not overflow to the 1st or 2nd day of the next month as appropriate (usual exceptions for February apply!) See example code below for examples. Reproduce code: --------------- <table><tr><th>Date</th><th>Expected Result</th><th>Actual Result</th><th>Pass/Fail?</th></tr><?php $arr_dates = array('2006-11-30 + 1 day' => '2006-12-01', '2006-11-30 + 2 days' => '2006-12-02', '2006-12-31 + 1 day' => '2007-01-01', '2006-06-31' => '2006-07-01', '2006-07-32' => '2006-08-01', '2006-11-31' => '2006-12-01', '2006-11-32' => '2006-12-02', '2006-12-32' => '2007-01-01'); foreach ($arr_dates as $source => $expected) { $result = date('Y-m-d', strtotime($source)); echo '<tr class="'.($result == $expected ? 'pass' : 'fail').'">'; echo '<td>'.$source.'</td>'; echo '<td>'.$expected.'</td>'; echo '<td>'.$result.'</td>'; echo '<td>'.($result == $expected ? 'Pass' : 'Fail').'</td>'; echo '</tr>'; } ?> </table> Expected result: ---------------- Results are contained above if you run it. Actual result: -------------- Actual results are contained above if you run it. -- Edit bug report at http://bugs.php.net/?id=39560&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39560&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39560&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39560&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=39560&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=39560&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=39560&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=39560&r=needscript Try newer version: http://bugs.php.net/fix.php?id=39560&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=39560&r=support Expected behavior: http://bugs.php.net/fix.php?id=39560&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=39560&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=39560&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=39560&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39560&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=39560&r=dst IIS Stability: http://bugs.php.net/fix.php?id=39560&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=39560&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=39560&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=39560&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=39560&r=mysqlcfg

« previous php.bugs (#105207) next »