1

How to find the start and end date of the week for a given year and week number? it is used for to insert the weeks dates for each employee in Work shift in the Hr module project,so kindly help me

Thanks in advance, shiva

SiKum
  • 95
  • 3
  • 6
  • Read here for information on the reverse problem: http://stackoverflow.com/questions/274861/how-do-i-calculate-the-week-number-given-a-date . Note that the algorithm for week numbers isn't universal. There is an ISO standard, ISO 8601, but not all countries follow it. Make sure your specifications clearly indicate which algorithm to use. – Klas Lindbäck Dec 02 '11 at 14:03

1 Answers1

0
function Start_End_Date_of_a_week($week, $year){
    $time = strtotime("1 January $year", time());
    $day = date('w', $time);
    $time += ((7*$week)+1-$day)*24*3600;
    $dates[0] = date('Y-n-j', $time);
    $time += 6*24*3600;
    $dates[1] = date('Y-n-j', $time);
    return $dates;
}

$result = Start_End_Date_of_a_week(35,1998);
echo 'Starting date of the week: '. $result[0]."\n";
echo 'End date the week: '. $result[1];