3rdLifeWebDev
asked on
Counting Specific "Day of the Week"s left in a month.
I need a php script that will count how many specific days of the week are left in a Month.
Eg. Today is Saturday, Sept 17. There are 2 Sundays left in this month.
I need to be able to count depending on specific days left.
Eg. Today is Saturday, Sept 17. There are 2 Sundays left in this month.
I need to be able to count depending on specific days left.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this:
function getDaysLeft($thisDate, $dNum) {
// DEFINE NAMES
$wkNames = Array(0=>"Sunday", 1=>"Monday", 2=>"Tuesday", 3=>"Wednesday", 4=>"Thursday", 5=>"Friday", 6=>"Saturday");
$countMonth = 0;
// SPLIT DATE
$sDate = explode("/",$thisDate);
$m = $sDate[0];
$d = $sDate[1];
$y = $sDate[2];
// LOOP THROUGH REST OF MONTH AND RETURN DAYS
while ($m == date("n",mktime(0,0,0,$m,$d,$y))) {
$newDate = date("w",mktime(0,0,0,$m,$d,$y));
if ($newDate == $dNum && isset($isDay)) { $countMonth++; echo $d . "|" . $m . "<BR>"; $d = $d + 7;}
else { $d++; $isDay = 0; }
}
return "There are " . $countMonth . " " . $wkNames[$dNum] . "'s left in " . date('F',mktime(0,0,0,$m,$d,$y));
}
echo getDaysLeft("8/31/2011", 4);
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
Best regards, ~Ray