php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64653 Subtraction of DateInterval yields wrong result.
Submitted: 2013-04-16 21:47 UTC Modified: 2021-04-05 15:18 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: eugen dot artus at gmx dot net Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.4.14 OS: Kubuntu 12.04
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:
MUST BE VALID
Solve the problem:
9 + 35 = ?
Subscribe to this entry?

 
 [2013-04-16 21:47 UTC] eugen dot artus at gmx dot net
Description:
------------
The test script below prints '2370-01-00' as the result, which is obviously wrong.

Test script:
---------------
<?php
    $date = new \DateTime('2370-01-31');
    echo $date->sub(new \DateInterval('P1M'))->format('Y-m-d'); 
?>


Expected result:
----------------
2369-12-31

Actual result:
--------------
2370-01-00

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-14 10:53 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2016-06-14 10:53 UTC] cmb@php.net
Verified: <https://3v4l.org/LpEF6>
 [2021-04-05 15:18 UTC] derick@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: derick
 [2021-04-05 15:18 UTC] derick@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at
http://www.php.net/downloads.php

This got fixed in PHP 7.2.0.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 07:01:31 2024 UTC