PHP gets the start and end dates of the first few weeks of the year

Source: Internet
Author: User
This article is mainly for you to share a PHP to get the first few weeks of the start date and the end date of the instance, has a good reference value, I hope to be helpful to everyone. Follow the small series together to see it, hope to help everyone.

The examples are as follows:

/** * Gets the start date and end date of the first few weeks of the year * @param int $year * @param int $week the first week;   */Public Function Weekday ($year, $week =1) {$year _start = mktime (0,0,0,1,1, $year);   $year _end = Mktime (0,0,0,12,31, $year);    Determines if the first day is the start of the first week if (intval (' W ', $year _start) ===1) {$start = $year _start;//The first day as the start of the first week}else{$week + +; $start = Strtotime (' +1 Monday ', $year _start);//start of the first Monday}//start of week if ($week ===1) {$weekday [' start '] = $sta   Rt }else{$weekday [' start '] = strtotime (' + '). (   $week -0). ' Monday ', $start);   }//End time of the week $weekday [' end '] = Strtotime (' +1 Sunday ', $weekday [' Start ']);   if (date (' Y ', $weekday [' End '])! = $year) {$weekday [' end '] = $year _end;  } return $weekday; }/** * Calculates the number of weeks of the year, starting from Monday, if the last day of the week after Thursday (including Thursday), is not counted as the last week of the year * If the first day is a full week before Thursday (including Thursday), it does not count towards the first week of the year * @param int $ye   AR * return int */Public Function Week ($year) {$year _start = mktime (0,0,0,1,1, $year);   $year _end = Mktime (0,0,0,12,31, $year); if (Intval (date (' W ', $year _end)) ===1) {RetuRN Date (' W ', Strtotime (' Last week ', $year _end));   }else{return date (' W ', $year _end); }  }

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.