1 function getWeek($startdate,$enddate) 2 { 3 //参数不能为空 4 if(!empty($startdate) && !empty($enddate)){ 5 6 //先把两个日期转为时间戳 7 $startdate=strtotime($startdate); 8 $enddate=strtotime($enddate); 9 //开始日期不能大于结束日期 10 if($startdate<=$enddate){ 11 $end_date=strtotime("next monday",$enddate); 12 if(date("w",$startdate)==1){ 13 $start_date=$startdate; 14 }else{ 15 $start_date=strtotime("last monday",$startdate); 16 } 17 //计算时间差多少周 18 $countweek=($end_date-$start_date)/(7*24*3600); 19 for($i=0;$i<$countweek;$i++){ 20 $sd=date("Y-m-d",$start_date); 21 $ed=strtotime("+ 6 days",$start_date); 22 $eed=date("Y-m-d",$ed); 23 $arr[]=array($sd,$eed); 24 $start_date=strtotime("+ 1 day",$ed); 25 } 26 return $arr; 27 } 28 } 29 }