This is the function I\'m trying to write:
function getWednesdays($month, $year) {
// Returns an array of DateTimes representing all Wednesdays this month
Use this function to get any days total count in a month
function getTotalDays($year, $month, $day){
$from = $year."-".$month."-01";
$t=date("t",strtotime($from));
for($i=1; $i<$t; $i++){
if( strtolower(date("l",strtotime($year."-".$month."-".$i)))== $day){
$count++;
}
}
return $count;
}
use like this getTotalDays('2014', '08','monday');
will output 4
But if you want all dates in a month on a particular day then use this function
function getTotalDatesArray($year, $month, $day){
$date_ar=array();
$from = $year."-".$month."-01";
$t=date("t",strtotime($from));
for($i=1; $i<$t; $i++){
if( strtolower(date("l",strtotime($year."-".$month."-".$i)))== $day){
$j= $i>9 ? $i: "0".$i;
$date_ar[]=$year."-".$month."-".$j;
}
}
return $date_ar;
}
use like this getTotalDatesArray('2014', '08','monday');
will output Array ( [0] => 2014-08-04 [1] => 2014-08-11 [2] => 2014-08-18 [3] => 2014-08-25 )