我正计算两个日期之间的天数,没有周末从javascript中的datepicker获取

时间:2016-01-25 05:45:06

标签: javascript php jquery datepicker

我正在使用此javascript使用以下代码获取两个日期选择器:

$('td', table).not('td [colspan=3]').addClass('ui-widget-content');

我想计算没有周末日期的日期之间的天数,并提醒计数日期。

2 个答案:

答案 0 :(得分:1)

var SUNDAY = 0;
var SATURDAY = 6;

Date.prototype.isWeekDay = function () {
    return this.getDay() != SATURDAY && this.getDay() != SUNDAY;
}

function getWorkingDaysBetween(startDate, endDate) {
    var d = startDate;
    var result = 0;
    while (d <= endDate) {
        if (d.isWeekDay())
            result++;
        d = d.addDays(1);
    }
    return result;
}

答案 1 :(得分:1)

function getDates($startTime, $endTime) {
  $day = 86400;
  $format = 'Y-m-d';
$startTime = strtotime($startTime);
$endTime = strtotime($endTime);
//$numDays = round(($endTime - $startTime) / $day) + 1;
$numDays = round(($endTime - $startTime) / $day); // remove increment 

$days = array();

    for ($i = 0; $i < $numDays; $i++) { //change $i to 1
    $days[] = date($format, ($startTime + ($i * $day)));
  }
return $days;

}

$date=array();
        $date=getDates($stCodate, $enCodate);
        //print_r( $date);
        $cntdate="0";
        foreach($date as $day ){
            echo date('D', strtotime( $day));
            $nmday=date('D', strtotime( $day));

            if(!($nmday=="Sat"||$nmday=="Sun")){
                $cntdate++;

            }
            //echo $cntdate;
        }