So I have an array of dates like this -
Contents of $monthsArray
2015-02-01
2015-03-01
2015-04-01
2015-05-01
2015-06-01
2015-07-01
2015-08-01
2015-09-01
2015-10-01
I want to loop through the array and minus one year from each date -
foreach ($monthsArray as $month)
{
$ytdFrom = date("$month", strtotime('-1 year'));
$ytdTo = $month;
}
The value from the first loop of $ytdFrom is still = 2015-02-01, and so on, the ytdFrom doesn't minus the one year.
Although If run the following code -
$ytdFrom= date('Y-m-d',strtotime('-1 year')); // Todays date 2016-02-01
This would = 2015-02-01.
I can't see why this is happening, strToTime requires a string as its parameter and that is exactly what I'm passing in.
Any Ideas?