[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 539
  • Last Modified:

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
0
revo1059
Asked:
revo1059
  • 2
  • 2
1 Solution
 
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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now