<!DOCTYPE html>
<html lang="en">
<head>
<title>Malasngoding.com - Menampilkan Jumlah Hari dalam Sebulan dengan PHP</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="container mt-3">
<h2>Menampilkan Jumlah Hari dalam Sebulan dengan PHP</h2>
<form action="" method="GET">
<div class="mb-3 mt-3">
<label>Tahun</label>
<select class="form-control" name="tahun" required>
<?php
$tahun = date('Y');
for($i=2022; $i<=$tahun; $i++){
?>
<option <?php if(isset($_GET['tahun'])==$i){echo "selected='selected'";} ?> value="<?php echo $i; ?>"><?php echo $i; ?></option>
<?php
}
?>
</select>
</div>
<div class="mb-3 mt-3">
<label>Bulan</label>
<select class="form-control" name="bulan" required>
<option <?php if(isset($_GET['bulan'])=="1"){echo "selected='selected'";} ?> value="1">Januari</option>
<option <?php if(isset($_GET['bulan'])=="2"){echo "selected='selected'";} ?> value="2">Februari</option>
<option <?php if(isset($_GET['bulan'])=="2"){echo "selected='selected'";} ?> value="3">Maret</option>
<option <?php if(isset($_GET['bulan'])=="4"){echo "selected='selected'";} ?> value="4">April</option>
<option <?php if(isset($_GET['bulan'])=="5"){echo "selected='selected'";} ?> value="5">Mei</option>
<option <?php if(isset($_GET['bulan'])=="6"){echo "selected='selected'";} ?> value="6">Juni</option>
<option <?php if(isset($_GET['bulan'])=="7"){echo "selected='selected'";} ?> value="7">Juli</option>
<option <?php if(isset($_GET['bulan'])=="8"){echo "selected='selected'";} ?> value="8">Agustus</option>
<option <?php if(isset($_GET['bulan'])=="9"){echo "selected='selected'";} ?> value="9">September</option>
<option <?php if(isset($_GET['bulan'])=="10"){echo "selected='selected'";} ?> value="10">Oktober</option>
<option <?php if(isset($_GET['bulan'])=="11"){echo "selected='selected'";} ?> value="11">November</option>
<option <?php if(isset($_GET['bulan'])=="12"){echo "selected='selected'";} ?> value="12">Desember</option>
</select>
</div>
<button type="submit" class="btn btn-primary">LIHAT</button>
</form>
<br>
<br>
<?php
if(isset($_GET['tahun']) && isset($_GET['bulan'])){
$tahun = $_GET['tahun'];
$bulan = $_GET['bulan'];
$tanggal = cal_days_in_month(CAL_GREGORIAN, $bulan, $tahun);
echo "Tahun : ".$tahun."<br>";
echo "Bulan : ".$bulan."<br>";
echo "Jumlah Hari: ".$tanggal;
}
?>
</div>
</body>
</html>