Get the friday of a given week number

Hello

I need a way to find the friday for a week number in php.  eg date("W") reports the week number of the current date.  I need a way to take week 14 and tell what day friday would be for that week

I am using php 4 and mysql 5
LVL 1
revo1059Asked:
Who is Participating?
 
star_trekCommented:
use the following in PHP

function getFriday($wk,$yr) {
    $wk = $wk-1;
    $stday = strtotime($wk.' week',mktime(0,0,0,1,1,$yr));
    $wk_num = date("w",$stday);
     $add_day = (5-$wk_num);
    $friday_date = date("Y-m-d",mktime(0,0,0,date("m",$stday),date("d",$stday)+$add_day,date("Y",$stday)));
    return $friday_date;
}

getFriday(5, 2006); //returns 2006-02-03, which is 5th friday of 2006
0
 
revo1059Author Commented:
star_trek,

I tried your code, and the page just displays blank.  
this is my exact code


<?php
function getFriday($wk,$yr) {
    $wk = $wk-1;
    $stday = strtotime($wk.' week',mktime(0,0,0,1,1,$yr));
    $wk_num = date("w",$stday);
     $add_day = (5-$wk_num);
    $friday_date = date("Y-m-d",mktime(0,0,0,date("m",$stday),date("d",$stday)+$add_day,date("Y",$stday)));
 
   return $friday_date;



}
getFriday(22,2006);

?>
0
 
star_trekCommented:

when you call the function, echo it browser as

echo getFriday(22,2006);
0
 
revo1059Author Commented:
I am what you would call a noob, that worked great.  Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.