Bug #67863 [Opn->Nab]: datetime->sub does not work well
Edit report at https://bugs.php.net/bug.php?id=67863&edit=1
ID: 67863
Updated by: requinix@php.net
Reported by: teamo dot um1 at mail dot ru
Summary: datetime->sub does not work well
-Status: Open
+Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: linux
PHP Version: 5.4.31
Block user comment: N
Private report: N
New Comment:
P1M means literally one month. 7/31 minus one month is 6/31, which "wraps" around to 7/1.
Previous Comments:
------------------------------------------------------------------------
[2014-08-19 12:09:35] teamo dot um1 at mail dot ru
Description:
------------
subsription of months does not work well for the last day of month
Test script:
---------------
$date = new \DateTime();
$date->setDate(2014, 7, 31);
$date->setTime(0,0,0);
print($date->format('Y-m-d'))."\n";
$date->sub(new \DateInterval('P1M'));
print($date->format('Y-m-d'))."\n";
->> 2014-07-31
->> 2014-07-01
must be 2014-06-30
$date->setDate(2014, 8, 31);
->> 2014-08-31
->> 2014-07-31
ok
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67863&edit=1
Thread (2 messages)