Skip to content

Instantly share code, notes, and snippets.

@kobus1998
Created October 16, 2019 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kobus1998/537452e4dba88e1668ae5d58032f7de7 to your computer and use it in GitHub Desktop.
Save kobus1998/537452e4dba88e1668ae5d58032f7de7 to your computer and use it in GitHub Desktop.
simple calendar
<?php
// start date current month
$day = 01;
$month = date('m');
$year = date('Y');
$today = date('d-m-Y');
$period = new DatePeriod(
new DateTime("$day-$month-$year"),
new DateInterval('P1D'),
new DateTime(date('t-m-Y'))
);
$days = [];
foreach($period as $day) {
$days[] = $day->format('d-m-Y');
}
$days = array_chunk($days, 7, true);
echo '<table>';
foreach($days as $dayRange)
{
echo '<tr>';
foreach($dayRange as $day)
{
echo '<td style="padding: 1rem; '.($day == $today ? 'color: orange;' : '').'">' . $day . '</td>';
}
echo '</tr>';
}
echo '</table>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment