php - How to display sundays in a month? -
i have been trying answer question , after r&d have come solution too
$begin = new datetime('2014-11-01'); $end = new datetime('2014-11-30'); $end = $end->modify('+1 day'); $interval = new dateinterval('p1d'); $daterange = new dateperiod($begin, $interval, $end); foreach ($daterange $date) { $sunday = date('w', strtotime($date->format("y-m-d"))); if ($sunday == 0) { echo $date->format("y-m-d") . "<br>"; } else { echo''; } }
try way:
$begin = new datetime('2014-11-01'); $end = new datetime('2014-11-30'); while ($begin <= $end) // loop work begin end date { if($begin->format("d") == "sun") //check day sunday here { echo $begin->format("y-m-d") . "<br>"; } $begin->modify('+1 day'); }
Comments
Post a Comment