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); } }