PHP gets this week's start time and last time based on week number

Source: Internet
Author: User

/** * Get this week's start time and last time according to week * @param int $year Year $weeks = Get_week ($year) * @param such as get start time of 18th week $weeks[18][0] * @param such as Get the last time of 18th week $weeks[18][1]*/    Static   Public functionGet_week ($year) {        $year _start=$year. "-01-01"; $year _end=$year. "-12-31"; $startday=Strtotime($year _start); if(intval(Date(' N ',$startday)! = ' 1 ') {            $startday=Strtotime("Next Monday",Strtotime($year _start));//get the date of the first week of the year        }        $year _mondy=Date("Y-m-d",$startday);//get the date of the first week of the year        $endday=Strtotime($year _end); if(intval(Date(' W ',$endday) = = ' 7 ') {            $endday=Strtotime("Last Sunday",Strtotime($year _end)); }        $num=intval(Date(' W ',$endday));  for($i= 1;$i<=$num;$i++) {            $j=$i-1; $start _date=Date("Y-m-d",Strtotime("$year _mondy $jWeek ")); $end _day=Date("Y-m-d",Strtotime("$start _date+6 Day ")); $week _array[$i] =Array (                Str_replace("-",                "",$start _date            ),Str_replace("-", "",$end _day)); }        return $week _array; }

PHP gets this week's start time and last time based on week number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.