php - get number day of month without Friday -
i need number of days in month, without example fridays.
$num = cal_days_in_month(cal_gregorian, $month, 2012); here can total number of days, need substract fridays count. how do it?
i found handy function here:
function num_days ($day, $month, $year) { $day_array = array("mon" => "monday", "tue" => "tuesday", "wed" => "wednesday", "thu" => "thursday", "fri" => "friday", "sat" => "saturday", "sun" => "sunday"); $month_array = array(1 => "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"); /* * check our arguments valid. */ /* * $day must either full day string or 3 letter abbreviation. */ if (!(in_array($day, $day_array) || array_key_exists($day, $day_array))) { return 0; } /* * $month must either full month name or 3 letter abrreviation */ if (($mth = array_search(substr($month,0,3), $month_array)) <= 0) { return 0; } /* * fetch previous $day of $month+1 in $year; * give last $day of $month. */ /* * calculate timestamp of 01/$mth+1/$year. */ $time = mktime(0,0,0,$mth+1,1,$year); $str = strtotime("last $day", $time); /* * return nth day of month. */ $date = date("j", $str); /* * if difference between $date1 , $date2 28 * there 5 occurences of $day in $month/$year, otherwise * there 4. */ if ($date <= 28) { return 4; } else { return 5; } } usage:
echo date('t', strtotime("$month 2012")) - num_days('friday', $month, 2012);
provided $month full name of month (not number).
Comments
Post a Comment