|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64347 Date object
Submitted: 2013-03-04 11:14 UTC Modified: 2015-01-20 21:16 UTC
Avg. Score:4.5 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:0 (0.0%)
From: alessio at alias2k dot com Assigned: derick (profile)
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS: Debian 6
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
41 - 26 = ?
Subscribe to this entry?

 [2013-03-04 11:14 UTC] alessio at alias2k dot com
From manual page:

When you have a datetime object you can modify the date adding or subtracting 
month. If you do that, the result is always unpredictable, because the mktime, 
the sub, or the modify function, always subtract the amount of days of the 
previous month. I'll make an example:
If I do
$date = new DateTime('2001-03-31');
$interval = new DateInterval('P1M');

echo $date->format('Y-m-d');
I obtain 2001-03-03 as result, but I've expected to have 2001-02-28, because the 
previous month is february, not 28 days first.
We have the same problem if we add some months to our starting date:

$date = new DateTime('2001-03-31');
$interval = new DateInterval('P1M');

echo $date->format('Y-m-d');
I obtain 2001-05-01 as result, but also in this case I've aspected a different 
result, i think the right value is 2001-04-30, because you have to add the days 
of the next month to obtain the right result, not the days of current month.
The problem is also the communication with mySql, because mySql calculate the 
right result, so the comparison between two date it's impossible

Test script:
$date = new DateTime('2001-03-31');
$interval = new DateInterval('P1M');

echo $date->format('Y-m-d');

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-05 17:21 UTC]
-Assigned To: +Assigned To: derick
 [2015-01-20 21:16 UTC]
-Status: Assigned +Status: Not a bug
 [2015-01-20 21:16 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

This is expected behaviour. +1 month and -1 month add or remove "1" from the month number. The dates look odd because the day count under or overflows.
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Fri Jul 20 10:01:25 2018 UTC