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
EDIT: note that this was inspired by khany's code above.
Here's a fully working script for my use-case, which is to display year+month strings from the current month going back N number of months. It should work with days or years as intervals and is tested with PHP version 5.3.3.
format('Ym'));
$previousMonthDate->sub(new DateInterval("P1M"));
}
print_r($monthDateList) . "\n";
?>
The output is:
Array
(
[0] => 201705
[1] => 201704
[2] => 201703
[3] => 201702
[4] => 201701
[5] => 201612
[6] => 201611
[7] => 201610
[8] => 201609
[9] => 201608
[10] => 201607
[11] => 201606
[12] => 201605
[13] => 201604
[14] => 201603
[15] => 201602
)