Bir tarih aralığında hafta gün sayısını hesaplamak

0 Cevap

Ben PHP kullanarak belirli bir tarih aralığında hafta gün sayısını (monda-Cuma) hesaplamak için çalışıyorum. Kullanıcı başlangıç ​​(2010-12-01) ve bitiş tarihini (2010-12-24) girerse, işlevi bu tarih aralığında hafta gün sayısını tükürmek gerekir.

Bu ne buldum ama yardımcı olmuyor ..

function getworkingdays_time($STARTSTAMP, $ENDSTAMP){

  $noofdays = ceil(($ENDSTAMP - $STARTSTAMP) / 86400);
    $sundaycounter = 0;
    $saturdaycounter = 0;
    $holidaycounter = 0;
    $offset = 0;
    $holidaycounter = check_holiday_range($STARTSTAMP, $ENDSTAMP);        // check holiday range


if(!defined("WORKSATURDAYS"))
{
    define("WORKSATURDAYS", 0);
}
if(!defined("WORKSUNDAYS"))
{
    define("WORKSUNDAYS", 0);
}  


    for ($i = 0; $i <= $noofdays; $i++){
        $ts = $STARTSTAMP + ($i * 86400);
        if (WORKSATURDAYS == '0' && date("l", $ts) == "Saturday"){
            ## they dont work saturdays
            $saturdaycounter ++;
        } elseif (WORKSUNDAYS == '0' && date("l", $ts) == "Sunday"){
            ## they dont work sundays
            $sundaycounter ++;
        }        
    }
    $total = $holidaycounter + $saturdaycounter + $sundaycounter;
    $offset = $total;
    if ($total > 0){
        $total = getworkingdays_time($ENDSTAMP + 86400, ($ENDSTAMP + ($total * 86400) + 86400));
        $offset += $total;
    }
    unset($holidaycounter, $saturdaycounter, $sundaycounter, $i, $noofdays, $ts, $total);
    return ($offset);
}

Any help will be greatly appreciated. Thanks heaps PSi

0 Cevap