更新时间:2022-12-09 18:00:21
$ datefrom = strtotime($ datefrom,0);
$ dateto = strtotime($ dateto,0);
$ difference = $ dateto - $ datefrom;
$ days_difference = floor($ difference / 86400);
$ weeks_difference = floor($ days_difference / 7); //完成周
$ first_day = date(w,$ datefrom);
$ days_remainder = floor($ days_difference%7);
$ odd_days = $ first_day + $ days_remainder; //剩下的是星期六还是星期天?
if($ odd_days> 7){//星期日
$ days_remainder--;
}
if($ odd_days> 6){//星期六
$ days_remainder--;
}
$ datediff =($ weeks_difference * 5)+ $ days_remainder;
从这里: http://www.addedbytes.com/php/php-datediff-function/
The title is pretty much self explanatory. Given two dates what is the best way of finding the number of week days using PHP? Week days being Monday to Friday.
For instance, how would I find out that there are 10 week days in between 31/08/2008
and 13/09/2008
?
$datefrom = strtotime($datefrom, 0);
$dateto = strtotime($dateto, 0);
$difference = $dateto - $datefrom;
$days_difference = floor($difference / 86400);
$weeks_difference = floor($days_difference / 7); // Complete weeks
$first_day = date("w", $datefrom);
$days_remainder = floor($days_difference % 7);
$odd_days = $first_day + $days_remainder; // Do we have a Saturday or Sunday in the remainder?
if ($odd_days > 7) { // Sunday
$days_remainder--;
}
if ($odd_days > 6) { // Saturday
$days_remainder--;
}
$datediff = ($weeks_difference * 5) + $days_remainder;
From here: http://www.addedbytes.com/php/php-datediff-function/