1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| <?php
$currentMonth = $_GET['month'] ?? date("m");
$currentMonth = intval($currentMonth);
$currentYear = $_GET['year'] ?? date("Y");
$currentYear = intval($currentYear);
$action = $_GET['action'] ?? null;
if($action == 'next') {
list($currentMonth,$currentYear) = nextMonth($currentMonth,$currentYear);
} else if ($action == 'prev') {
list($currentMonth,$currentYear) = prevMonth($currentMonth,$currentYear);
}
function nextMonth($selectedMonth,$selectedYear)
{
$dt = new DateTime($selectedYear.'-'.$selectedMonth.'-01');
$dt->add(new DateInterval('P1M'));
return [$dt->format('m'),$dt->format('Y')];
}
function prevMonth($selectedMonth,$selectedYear)
{
$dt = new DateTime($selectedYear.'-'.$selectedMonth.'-01');
$dt->sub(new DateInterval('P1M'));
return [$dt->format('m'),$dt->format('Y')];
}
?>
<div>
<a href="?month=<?=$currentMonth?>&year=<?=$currentYear?>&action=prev"> < </a>
<label class="LabelSelectedMonth"><?php echo $currentMonth.'/'.$currentYear;?></label>
<a href="?month=<?=$currentMonth?>&year=<?=$currentYear?>&action=next"> > </a>
</div> |