根据周数获取当周的起始日期

//根据第几周获取当周的开始日期与最后日期
    private function getWeekDate($year,$weeknum){ 
        $firstdayofyear=mktime(0,0,0,1,1,$year); 
        $firstweekday=date('N',$firstdayofyear); 
        $firstweenum=date('W',$firstdayofyear); 
        if($firstweenum==1){ 
            $day=(1-($firstweekday-1))+7*($weeknum-1); 
            $startdate=date('Y-m-d',mktime(0,0,0,1,$day,$year)); 
            $enddate=date('Y-m-d',mktime(0,0,0,1,$day+6,$year)); 
        }else{ 
            $day=(9-$firstweekday)+7*($weeknum-1); 
            $startdate=date('Y-m-d',mktime(0,0,0,1,$day,$year)); 
            $enddate=date('Y-m-d',mktime(0,0,0,1,$day+6,$year)); 
        } 
        $weekDate['sart_date'] = $startdate;
        $weekDate['end_date'] = $enddate;

        return $weekDate;     
    }


    $year = 2020;
    $weeknum = 10;
    $time = $this->getWeekDate($year,$weeknum);
    dump($time);die;

运行结果:

根据周数获取当周的起始日期_第1张图片

你可能感兴趣的:(根据周数获取当周的起始日期)