1function getSundays($y, $m) {
2 return new DatePeriod(
3 new DateTime("first sunday of $y-$m"),
4 DateInterval::createFromDateString('next sunday'),
5 new DateTime("last day of $y-$m")
6 );
7}
8
9// Usage:
10foreach (getSundays(2021, 03) as $sundays) {
11 echo $sundays->format("l, Y-m-d\n");
12}