I want to create a DatePeriod object with a negative DateInterval.
This creates a DatePeriod with the year increasing from today to 2016.
$this->S
According to comment by kevinpeno at 17-Mar-2011 07:47 on php.net's page about DateInterval::__construct(), you cannot directly create negative DateIntervals through the constructor:
new DateInterval('-P1Y'); // Exception "Unknown or bad format (-P1Y)"
Instead of this you are required to create a positive interval and explicitly set it's invert
property to 1
:
$di = new DateInterval('P1Y');
$di->invert = 1; // Proper negative date interval
Just checked the above code by myself, it's working exactly in this way.