PHP

Menghitung hari kerja dengan PHP

Berikut cara menghitung hari kerja dan menampilkan tanggal libur dalam satu bulan :

function countDays($year, $month, $ignore) {
    $count = 0;
    $exception = "";
    $counter = mktime(0, 0, 0, $month, 1, $year);
    while (date("n", $counter) == $month) {
        if (in_array(date("w", $counter), $ignore) == false) {
            $count++;
        } else {
            $exception = $exception." ".date("d", $counter);
        }
        $counter = strtotime("+1 day", $counter);
    }
    return  $count." Days, exception:".$exception;
}
echo countDays(2019, 4, array(0,6));

Terima Kasih, Selamat Mencoba.



0 Comments


Leave a Reply

Scroll to Top