How to iterate day in php? -
i need next 7 (or more) dates except sunday. firstly did
$end_date = new datetime(); $end_date->add(new dateinterval('p7d')); $period = new dateperiod( new datetime(), new dateinterval('p1d'), $end_date );
and after checked $period
in foreach
. noticed if remove sunday need add 1 more day end , each time when sunday is... there way it?
$start = new datetime(''); $end = new datetime('+7 days'); $interval = new dateinterval('p1d'); $period = new dateperiod($start, $interval, $end); foreach ($period $dt) { if ($dt->format("n") === 7) { $end->add(new dateinterval('p1d')); } else { echo $dt->format("l y-m-d") . php_eol; } }
Comments
Post a Comment