Link to home
Start Free TrialLog in
Avatar of tim_carter
tim_carter

asked on

PHP Date Object, Find last friday in a month

Hi Guys

I need to find out what date the last friday in a month is. Is there a way of doing this with php?

Thanks
Avatar of tim_carter
tim_carter

ASKER

I found out a way my self. Thanks

$NumberOfDaysInCurrentMonth=cal_days_in_month(CAL_GREGORIAN,$Month,$Year);
      
      $LastFridayIs = 0;
      for ($i=1;$i<$NumberOfDaysInCurrentMonth;$i++){
            $DayNameTemp = date("D", mktime(0, 0, 0, $Month, $i, $Year));
            if($DayNameTemp=='Fri')
                  $LastFridayIs = $i;
      }
      echo "LastFridayIs=".$LastFridayIs."<br>";
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Marcus Bointon
Marcus Bointon
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@Squinky: Very cool!  strtotime() is sheer genius! ~Ray
Thanks guys. Awesome ;) I just found out about the strtotime yesterday.. If only knew about that earlier, it could have saved me so much thinking ;)
Right, strtotime() always beats thinking for me!  

You might enjoy some of the books from SitePoint:
http://www.sitepoint.com/books/library/

They are usually pretty good.  Happy coding!