//e.g.
//$firstDate='2017-12-5';
//$lastDate='2020-1-3';
function calculateWeeks($firstDate='',$lastDate='')
{
$lastTime=date_timestamp_get(date_create($lastDate)); //1512403200
$firstTime=date_timestamp_get(date_create($firstDate)); //1577980800
//一年的第几周
$lastWeekNum=date('W',$lastTime); //01
$firstWeekNum=date('W',$firstTime); //49
//周属于哪一年
$lastWeek_Year=date('o',$lastTime); //2020
$firstWeek_Year=date('o',$firstTime); //2017
//中间年份周数
//2017~2020 中间有两年完整年 (2020-2017-1)*52
$through_Years_Weeks=($lastWeek_Year-$firstWeek_Year-1)*52; //104
$first_Year_weeks=52-$firstWeekNum+1; //4
$last_Year_weeks=$lastWeekNum; //01
$weeks=$through_Years_Weeks+$first_Year_weeks+$last_Year_weeks; //109
return $weeks;
}
网友评论