I'm able to show days from current date to next 3 months with this code:
$begin = new DateTime();
$end = new DateTime(date('Y-m-d', strtotime('+3 months', strtotime(date("d-m-Y")))));
$interval = DateInterval::createFromDateString('1 day');
$days = new DatePeriod($begin, $interval, $end);
foreach ( $days as $day ) {
...
}
I feel the code can be shortened especially for $end
. Could you help?
Oh, I also want to get previous 3 months. I changed '+3 months'
to '-3 months'
but no luck. Any ideas?