Example #1
0
}
function getMondays($y, $m)
{
    return new DatePeriod(new DateTime("first monday of {$y}-{$m}"), DateInterval::createFromDateString('next monday'), new DateTime("last day of {$y}-{$m}"));
}
echo "<table border=\"2\"";
echo "<tr>";
echo "<th>Mon</th>";
echo "<th>Tue</th>";
echo "<th>Wed</th>";
echo "<th>Thu</th>";
echo "<th>Fri</th>";
echo "<th>Sat</th>";
echo "<th>Sund</th>";
echo "</tr>";
foreach (getSundays(2015, 10) as $lazySundays) {
    echo "<tr>";
    echo "<td>" . $lazySundays->format("dS , F , Y") . "</td>";
    echo "</tr>";
}
echo "</table>";
echo "<table border=\"2\"";
echo "<tr>";
echo "<th>Mon</th>";
echo "<th>Tue</th>";
echo "<th>Wed</th>";
echo "<th>Thu</th>";
echo "<th>Fri</th>";
echo "<th>Sat</th>";
echo "<th>Sund</th>";
echo "</tr>";
<?php

foreach (getSundays(2014, 8) as $sunday) {
    echo $sunday->format("jS F, Y\n");
}
function getSundays($year, $month)
{
    $endMonth = $month + 1;
    return new DatePeriod(new DateTime("first sunday of {$year}-{$month}"), DateInterval::createFromDateString('next sunday'), new DateTime("first day of {$year}-{$endMonth}"));
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Non-Repeating Digits</title>
</head>
<body>
    <div>
        <?php 
date_default_timezone_set("Europe/Sofia");
$month = date('m');
$year = date('Y');
$sundays = getSundays($month, $year);
function getSundays($month, $year)
{
    $sun = strtotime('first Sunday of ' . $month . $year);
    $sundays = array();
    do {
        $sundays[] = new DateTime(date('r', $sun));
        $sun = strtotime('+7 days', $sun);
    } while (date('m', $sun) == $month);
    return $sundays;
}
foreach ($sundays as $sunday) {
    echo $sunday->format('jS F, Y') . "<br />\n";
}
?>
    </div>
</body>
</html>
<?php

// Source: http://stackoverflow.com/questions/4293174/grab-all-wednesdays-in-a-given-month-in-php
function getSundays($y, $m)
{
    return new DatePeriod(new DateTime("first sunday of {$y}-{$m}"), DateInterval::createFromDateString('next sunday'), new DateTime("last day of {$y}-{$m}"));
}
foreach (getSundays(date("Y"), date("M")) as $sunday) {
    echo $sunday->format("jS F Y") . "<br />";
}