Bug #75468 [Opn]: Adding +1 month using DateTime, it returns incorrect DateTime.
| From: | info at milinka dot co dot uk | Date: | Tue, 31 Oct 2017 10:29:39 +0000 |
| Subject: | Bug #75468 [Opn]: Adding +1 month using DateTime, it returns incorrect DateTime. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-212386@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75468&edit=1
ID: 75468
User updated by: info at milinka dot co dot uk
Reported by: info at milinka dot co dot uk
Summary: Adding +1 month using DateTime, it returns incorrect
DateTime.
Status: Open
Type: Bug
Package: Date/time related
Operating System: any
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
$date = new DateTime();
$date->setDate(2017, 1, 31);
$date->modify("+1 months");
var_dump($date->format('d.m.Y'));
--> "2017-03-03 03:25:01.010311"
Previous Comments:
------------------------------------------------------------------------
[2017-10-31 09:48:40] info at milinka dot co dot uk
Description:
------------
NOTE: This bug can replicated only today. 31 Oct 2017.
When adding +1 month using DateTime, it returns incorrect DateTime.
Code:
$begin = new DateTime("now");
$end = clone $begin;
$end->modify("+1 month");
var_dump($begin,$end);
Outputs dates, where end date is wrong:
object(DateTime)#1 (3) {
["date"]=>
string(26) "2017-10-31 02:41:11.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(10) "US/Pacific"
}
object(DateTime)#2 (3) {
["date"]=>
string(26) "2017-12-01 02:41:11.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(10) "US/Pacific"
}
Test script:
---------------
$begin = new DateTime("now");
$end = clone $begin;
$end->modify("+1 month");
var_dump($begin,$end);
Expected result:
----------------
object(DateTime)#1 (3) {
["date"]=>
string(26) "2017-10-31 02:41:11.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(10) "US/Pacific"
}
object(DateTime)#2 (3) {
["date"]=>
string(26) "2017-11-30 02:41:11.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(10) "US/Pacific"
}
Actual result:
--------------
object(DateTime)#1 (3) {
["date"]=>
string(26) "2017-10-31 02:41:11.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(10) "US/Pacific"
}
object(DateTime)#2 (3) {
["date"]=>
string(26) "2017-12-01 02:41:11.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(10) "US/Pacific"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75468&edit=1