We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Get the friday of a given week number

revo1059
revo1059 asked
on
Medium Priority
572 Views
Last Modified: 2013-12-12
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
Comment
Watch Question

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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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);

?>

when you call the function, echo it browser as

echo getFriday(22,2006);

Author

Commented:
I am what you would call a noob, that worked great.  Thank you
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.