PyraX Posted April 17, 2008 Share Posted April 17, 2008 Hi I need script that gives me the day of every friday in the month given the variables year and month in an array. for example this month would be 4,11,18,25 Can anyone help me with this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/101479-every-friday-in-the-month/ Share on other sites More sharing options...
DJTim666 Posted April 17, 2008 Share Posted April 17, 2008 <?php $month = 1; //supply month # $year = 1998; //supply year $date = mktime(0, 0, 0, $month, 0, $year); $i = 1; $days = date("t", $date); while ($i <= $days) { $find_date = mktime(0, 0, 0, $month, $i, $year); if (date("l", $find_date) == "Friday") { echo "Day $i is a Friday on month #$month.<br />"; } $i++; } ?> Edit: Works fine . Quote Link to comment https://forums.phpfreaks.com/topic/101479-every-friday-in-the-month/#findComment-519109 Share on other sites More sharing options...
benphp Posted April 17, 2008 Share Posted April 17, 2008 Dang that's slick. I didn't think of using the weekname. I did it the very hard way. Quote Link to comment https://forums.phpfreaks.com/topic/101479-every-friday-in-the-month/#findComment-519113 Share on other sites More sharing options...
PyraX Posted April 17, 2008 Author Share Posted April 17, 2008 Thanks so much DJTim666 Here is the final code: $month = $m; //supply month # $year = $y; //supply year $timestamp = strtotime("$m/01/$y"); $date = mktime(0, 0, 0, $month, 0, $year); $i = 1; $days = idate("t",$timestamp); while ($i <= $days) { if (date("l",strtotime("$m/$i/$y")) == "Friday") { echo "Day $i is a Friday on month #$month<br>"; } $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/101479-every-friday-in-the-month/#findComment-519116 Share on other sites More sharing options...
DJTim666 Posted April 17, 2008 Share Posted April 17, 2008 I know it says solved, but I don't think you got the updated script. You don't need all that strtotime stuff in your re-written script. mktime returns the timestamp of the month/year/day/hour/minute/second supplied. Anyways, glad I could be of help . -- DJ Quote Link to comment https://forums.phpfreaks.com/topic/101479-every-friday-in-the-month/#findComment-519117 Share on other sites More sharing options...
PyraX Posted April 17, 2008 Author Share Posted April 17, 2008 Question for you, how would you turn this into x number of days after a date. for example 14 days after 2008-04-18 Quote Link to comment https://forums.phpfreaks.com/topic/101479-every-friday-in-the-month/#findComment-519134 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.