phpllama Posted September 25, 2009 Share Posted September 25, 2009 Hi. I'm trying to get my script to produce the date of every Friday of the current month. But I have no idea how to do it $date = time(); $month = date('F', $date); So I've got the current month but how do you get the Friday from every week of the month? Quote Link to comment Share on other sites More sharing options...
5kyy8lu3 Posted September 25, 2009 Share Posted September 25, 2009 http://us2.php.net/manual/en/function.date.php Quote Link to comment Share on other sites More sharing options...
cjb Posted September 26, 2009 Share Posted September 26, 2009 This will display every Friday of the current month, use the array $fridays for the unix time. Let me know if you have any questions. $now = time(); $nowYear = date('Y', $now); $nowMonth = date('n', $now); $nowDay = date('j', $now); $uFirstDay = mktime(0,0,0,$nowMonth,1,$nowYear); $uLastDay = mktime(0,0,0,$nowMonth+1, 0, $nowYear); $firstDay = date('D', $uFirstDay); $fridays = array(); $fridaysCount = 0; $day = $uFirstDay; while($day <= $uLastDay){ $weekday = date('D', $day); if($weekday == "Fri"){ $fridays[$fridaysCount] = $day; echo date('D, M j, Y', $day) . "<br>"; $fridaysCount++; } $day = $day + (60*60*24); } echo "<br><br>There are $fridaysCount Fridays this month<br>$fridays[0],$fridays[1],$fridays[2],$fridays[3]"; Quote Link to comment 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.