If I already know the year and the week of the year (52 weeks in a year), calculate the initial date and end date of the week. The Code is as follows: 1 functionGetWeekDate ($ year, $ week) 2 {3 $ monthsarray (1Jan ., 2Feb ., 3Mar ., 4Apr ., 5May ., 6Jun ., 7Jul ., 8Aug.
If I already know the year and the week of the year (52 weeks in a year), calculate the initial date and end date of the week. The Code is as follows: 1 function GetWeekDate ($ year, $ week) 2 {3 $ months = array ("1" = "Jan. "," 2 "=" Feb. "," 3 "=" Mar. "," 4 "=" Apr. "," 5 "=" May. "," 6 "=" Jun. "," 7 "=" Jul. "," 8 "=" Aug."
If I already know the year and the week of the year (52 weeks in a year), calculate the initial date and end date of the week. The Code is as follows:
1 function GetWeekDate ($ year, $ week) 2 {3 $ months = array ("1" => "Jan. "," 2 "=>" Feb. "," 3 "=>" Mar. "," 4 "=>" Apr. "," 5 "=>" May. "," 6 "=>" Jun. "," 7 "=>" Jul. "," 8 "=>" Aug. "," 9 "=>" Sep. "," 10 "=>" Oct. "," 11 "=>" Nov. "," 12 "=>" Dec. "); 4 $ time = strtotime (" 1 January $ year ", time (); 5 $ day = date ('w', $ time ); // calculate the day of week 1st on April 9. 0 indicates Monday, 6 indicates Sunday 6 $ time + = (7 * ($ week-1) + 1-$ day) * 24*3600; // The time returns to the first day of the first week of the year, because January 1, January 1 is not necessarily Monday 7 $ m1 = date ('M', $ time ); 8 $ d1 = date ('D', $ time); 9 $ time + = 6*24*3600; // The interval between the start time and end time of a week is 10 $ m2 = date ('M', $ time); 11 $ d2 = date ('D', $ time ); 12 return $ year. "the week ". $ week. 'th ('. $ months [(int) $ m1]. $ d1 .'-'. $ months [(int) $ m2]. $ d2. ')'; 13}
Test results:
$ Year = 2014;
$ Week = 7; // week 7
Echo GetWeekDate ($ year, $ week); // the result is: 2014 the week 7th (Feb.10-Feb.16)
The initial time (Monday) for the seventh week of January 1, 2014 is 2014.2.10, and the end time (Sunday) is 2014.2.16.