There are two variables:

$week // номер недели (51) $year // номер года (2015) 

To determine the beginning and end of a particular week (current year) it turned out:

 $first_day = strtotime($week-date("W")." week -".( date("w")==0?6:date("w")-1 )." day 0:00:00"); $p = date("dmY 23:59:59",$first_day); $last_day = date("dmY", strtotime($p.'+6days ')); 

I do not know how much is written on Feng Shui, but it determines the dates correctly.

We must now determine the same dates, but only for 2015 (2014) year. Tell me how best to do.

    1 answer 1

     $week=51; $year=2015; $fy=date("w",mktime(0,0,0,1,1,$year)); // День недели 1 января нужного года if(!$fy) $fy=7; // Коррекция воскресенья $first=mktime(0,0,0,1,2-$fy+($week-1+($fy/5&1))*7,$year); // Понедельник недели на которой начался год + дней до нужной недели $last=$first+6*24*3600; // Еще 6 дней if($week<1 || ($week>52 && $year!=date("Y",$first))) print("Incorrect week"); print "First day: ".date("MdY",$first)." last day: ".date("MdY",$last)."\n"; 
    • Your example is almost correct, but it displays the dates of 52 weeks from December 21 to December 27, and Week 51 from December 14 to December 20 - thecoder
    • @thecoder Well, yes, I agree, it was not worth adding 7 days for the first week, corrected. You can $week*7-$fy-5 , so shorter, but not clearer :) - Mike
    • Now is correct :) But, if you specify $ week = 2; $ year = 2016; then it displays the dates of the first week of 2016 from 4 to 10 January, and it should be from 11 to 17, i.e. second week - thecoder
    • @thecoder The first week of January from Dec 28. 2015 to 01/03/2016, the second from 4 to 10. You’ll decide to count from zero weeks or 1 ... - Mike
    • In all calendars, the period from 28.12 to 03.01 is 53 weeks. You can see here week.4id.me/2015/53 - thecoder