|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2018-11-29 16:35 UTC] cmb@php.net
[2018-11-29 16:35 UTC] cmb@php.net
-Status: Open
+Status: Not a bug
-Assigned To:
+Assigned To: cmb
[2018-11-29 16:35 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 15:00:01 2025 UTC |
Description: ------------ If substract 1 Month for 31/30/29 march => Not correctly subtract (possible problem to February Month). Test script: --------------- <?php $intervalMonth = new DateInterval('P1M'); $dates = ['2019-01-30', '2019-02-28', '2019-03-29', '2019-03-30', '2019-03-31', '2019-04-30']; foreach($dates as $date){ $d = new DateTime($date); // Substract 1 Month $d->sub($intervalMonth); $subMonth = $d->format('Y-m-d'); // Adding 1 Month $d->add($intervalMonth); $addMonth = $d->format('Y-m-d'); // Echo information if(substr($date, 0, 7) === '2019-03'){ echo '*'; } echo 'Now: '.$date.'; Sub 1Month: '.$subMonth."; Add Month: ".$addMonth."\n"; } echo "\n"; echo '* BUG'; Actual result: -------------- Now: 2019-01-30; Sub 1Month: 2018-12-30; Add Month: 2019-01-30 Now: 2019-02-28; Sub 1Month: 2019-01-28; Add Month: 2019-02-28 *Now: 2019-03-29; Sub 1Month: 2019-03-01; Add Month: 2019-04-01 *Now: 2019-03-30; Sub 1Month: 2019-03-02; Add Month: 2019-04-02 *Now: 2019-03-31; Sub 1Month: 2019-03-03; Add Month: 2019-04-03 Now: 2019-04-30; Sub 1Month: 2019-03-30; Add Month: 2019-04-30 * BUG