php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67863 datetime->sub does not work well
Submitted: 2014-08-19 12:09 UTC Modified: 2014-08-19 17:07 UTC
From: teamo dot um1 at mail dot ru Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.4.31 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: teamo dot um1 at mail dot ru
New email:
PHP Version: OS:

 

 [2014-08-19 12:09 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-19 17:07 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-08-19 17:07 UTC] requinix@php.net
P1M means literally one month. 7/31 minus one month is 6/31, which "wraps" around to 7/1.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 08:00:02 2026 UTC