Bug #67863 [Opn->Nab]: datetime->sub does not work well

From: Date: Tue, 19 Aug 2014 17:07:04 +0000
Subject: Bug #67863 [Opn->Nab]: datetime->sub does not work well
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187183@lists.php.net to get a copy of this message
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)

« previous php.bugs (#187183) next »