|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77072 DateInterval constructor should provide a way to construct a negative interval
Submitted: 2018-10-27 17:24 UTC Modified: 2021-04-06 18:43 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: teo8976 at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 7.3.0RC4 OS: all
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: teo8976 at gmail dot com
New email:
PHP Version: OS:


 [2018-10-27 17:24 UTC] teo8976 at gmail dot com
A DateInterval object can represent negative intervals, when its $invert property equals 1.

However, there's no way (or no documented way) to construct a DateInterval object that is inverted with the constructor.

Yoy need to do:
  $interval = new DateInterval("whatever"); 
  $interval->inverted = 1;

It's absolutely ridiculous and pathetic that there exist values that can be represented by the class but cannot be created with the constructor.

The interval_spec should support a way to specify inverted intervals.
Any of these would be fine, it's just a matter of taste:
- prefix the interval with a "-" (minus) sign
  e.g. "-P1Y3D"
- a "-" (minus) sign after the initial P
  e.g. "P-1Y3D"
- some suffix at the end, for example "I" for "Inverted"
  e.g. "P1Y3DN"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-27 18:41 UTC]
-Package: PHP Language Specification +Package: Date/time related
 [2018-10-27 18:41 UTC]
ISO 8601's syntax does not support negative intervals so PHP shouldn't either, but the constructor could have a second $inverted=0 argument.
 [2019-02-11 19:25 UTC]
It is actually possible to set the invert property when constructing with 2 dates:

So a second $invert argument on the constructor would be weird in this scenario. I don't think this should be added
 [2021-04-06 18:43 UTC]
-Status: Open +Status: Not a bug
 [2021-04-06 18:43 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

 [2021-04-06 20:08 UTC] php4fan at gmail dot com
This is stupid.

I know the behavior matches the documentation, but it's ridiculous nonetheless. It's a design flaw and it needs to be fixed.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 28 01:01:31 2024 UTC