PHP code example of obokaman / dateranger

1. Go to this page and download the library: Download obokaman/dateranger library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

obokaman / dateranger example snippets




ateRanger\Period\Year;

$year = new Year();

echo "<h1>{$year->start()->format('Y')}</h1>";
foreach ($year as $month) {
    echo "<table><caption>{$month->start()->format('F')}</caption>";
    echo "<thead><tr><th></th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th><th>Sun</th></tr></thead><tbody>";
    foreach ($month as $week) {
        echo "<tr><td><small>{$week->start()->format('W')}</small></td>";
        foreach ($week as $day) {
            if (!$day->overlaps($month)) $day_color = '#ddd;';
            elseif ($day->isHoliday()) $day_color = 'red;';
            else $day_color = '#333';

            echo "<td style='border:1px solid #ccc;color:{$day_color}'>";
            echo $day->start()->format('d') . '</td>';
        }
        echo '</tr>';
    }
    echo '</tbody></table>';
}


$year = Year::fromYear(2014);
echo count($year); // returns 12.

$month = new Month('2014-01-01');
echo count($month) . PHP_EOL; // returns 5 (weeks).

echo $month->start()->format('F') . PHP_EOL; // returns 'January'.
foreach ($month as $week) {
    foreach ($week as $day) {
        if ($month->isOutOfMonth($day)) continue;
        echo $day->start()->format('Y-m-d') . PHP_EOL; // returns 2014-01-01\n [...]
    }
}