我需要获取两个日期之间一周中每一天的天数,例如:
2013-01-01 to 2013-01-15
Mo:2
Tu:3
We:2
Th:2
Fr:2
Sa:2
Su:2
我有这段代码不确定我以前从哪里得到它,但它似乎正在工作,但意识到它在某些日期范围内不起作用,例如 2013-03-01 到 2013-03-11 它报告星期一为 1 天而不是 2 天.
function daysOfWeekBetween($start_date, $end_date, $weekDay)
{
$first_date = strtotime($start_date." -1 days");
$first_date = strtotime(date("M d Y",$first_date)." next ".$weekDay);
$last_date = strtotime($end_date." +1 days");
$last_date = strtotime(date("M d Y",$last_date)." last ".$weekDay);
return floor(($last_date - $first_date)/(7*86400)) + 1;
}
daysOfWeekBetween($date_range['start_date'], $date_range['end_date'], 'Monday');