O-w Week converted to the last day of the normal date week public function Weektodate ($oW) { $oW = explode ("-", $oW); Split o-w Zhou Weihin and weeks $year = $oW [0];//year $week = $oW [1];//week number $weekYearBegin = Date ("W", Strtotime ($year. ") -01-01 ")); The beginning of January 1 is the day of the week, 0-6,0 is Sunday, 1-6 is Monday to Saturday $WYearBegin = Date ("W", Strtotime ($year. " -01-01 ")); The beginning of January 1 is the first week of the year, which may be the start of the month: 01, or the last week of the past: if ($WYearBegin = = "") { //The first week of the year $days = (7-$weekYearBegin)% 7 + (int) ($week-$WYearBegin) *7; Need to calculate the last day of the week (Sunday), distance from the beginning of January 1 How many days }else{ //last week of previous year $days = (7-$weekYearBegin)%7 + (int) ($week) *7; The last day of the week to be calculated (Sunday), the number of days from the beginning of January 1 } $lastDayOfW = Date ("y-m-d", Strtotime ($year. " -01-01 + ". $days." Days ")); Because it is the last day (Sunday), it must fall in the year ($year), or the next year, and not fall in the previous year with $year +n days return $lastDayOfW; }
The above is implemented for the entire code, and returns the date ("y-m-d") of the Last Day (Sunday) of the week of the date ("O-w").
PHP Week converted to date (last day) dates ("O-w") to y-m-d date--Post code