php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64052 PHP DateTime Add and sub
Submitted: 2013-01-23 03:07 UTC Modified: 2013-01-23 10:41 UTC
From: moses dot liao at techlinkz dot net Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.21 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: moses dot liao at techlinkz dot net
New email:
PHP Version: OS:

 

 [2013-01-23 03:07 UTC] moses dot liao at techlinkz dot net
Description:
------------
Using the current datetime, adding and subtracting one month does not result in an actual one month addition and subtraction

Test script:
---------------
        <td valign="top">
	    <?php

	    $previousMonth = new DateTime ('2013-03-31');
	    $previousMonth->sub (new DateInterval ('P1M'));
	    echo $previousMonth->format ('Y-m-d');

	    ?>
        </td>

        <td valign="top">
	    <?php

	    $nextMonth = new DateTime ('2013-03-31');
	    $nextMonth->add (new DateInterval ('P1M'));
	    echo $nextMonth->format ('Y-m-d');

	    ?>
        </td>


Expected result:
----------------
previous month to show 2013-02-*, next month to show 2013-04-*

Actual result:
--------------
<td>2013-03-03</td><td>2013-05-01</td>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-23 10:41 UTC] derick@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

This has been filed so many times, and it's still not a bug. For a full explanation, see: http://derickrethans.nl/obtaining-the-next-month-in-php.html
 [2013-01-23 10:41 UTC] derick@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 10 13:01:34 2025 UTC