I have a week number of the year and the week day, I need to get the exact date.
This is what I have tried so far. I found this code on stack overflow but it is not accurate:
function required_date($week_num, $day) {
$week_of_year = sprintf('%02d', date('W', strtotime(date('Y-m-01'))) + $week_num);
$day_of_week = date('N', strtotime($day));
$timestamp = strtotime(date('Y') . '-W' . $week_of_year . '-' . $day_of_week);
return $timestamp;
}
$timestamp = required_date(8, 'wednesday');
echo date('Y-m-d', $timestamp);
OUTPUT: 2014-03-26
EXPECTED OUTPUT: The 8th week and day wednesday has date 2014-02-19 according to the calendar.