Currently the last years date is off by 2 days. In other words, if I run a report today 8/14/2016 the date last year on this day(sunday) should be 8/16/2015 and it's showing 8/14/2015.
The code that's currently in place is
$date = new DateTime($current_time);
$day = $date->format('l');
$date->sub(new DateInterval('P1Y')); // back 1 year
$date->modify('next ' . $day);
$date->modify('next ' . $day);
Since P1Y doesn't take into account leap year and a few other things after reading about it, I read adding what I added below fixes that problem but it doesn't fix it.
$date = new DateTime($current_time);
$i = new DateInterval('P1Y');
$now = new DateTime;
while ($date >= $now) {
echo $date->format('c') . PHP_EOL;
$date = $date->sub($i);
}
This code gives me the same 8/14/2015.
Can someone tell me what I'm doing wrong?