PHP – gate list of day by passing day Sunday, Monday

In this post we show you how to gate list of day by passing day(Sunday, Monday, etc… or number of days).

function dates_of_month() : This function is use for get all list of date by give day. In this function we pass date in number like 0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday.

function dates_of_monthby_day() : This function is use for get all list of date by give day. In this function we pass date in name like Mon, Tue etc..

// this function is use for get date of month by given day
// Note : day is in number 
//  0 = Sunday,  1 = Monday,  2 = Tuesday,  3 = Wednesday, 4 = Thursday,  5 = Friday,  6 = Saturday
function dates_of_month($month,$year,$day_name)
{
    // cal days in month
    $num = cal_days_in_month(CAL_GREGORIAN, $month, $year);
    $dates_month = array(); // assign array 
    for($index = 1 ; $index <= $num ; $index++)
    {
        $make_time = mktime(0,0,0,$month,$index,$year);
        $date = date("d-M-Y", $make_time);

        $date_day = date('w',$make_time); 
        if($date_day == $day_name)
        {
            $dates_month[$index] = $date;
        }  
    }
    $_dates = array_values($dates_month);
    return $_dates;  // return date  in array 
}

// this function is use for get date of month by given day
// Note : day is name
//  like Mon, Tue etc...
function dates_of_monthby_day($month,$year,$day_name)
{
    // cal days in month
    $num = cal_days_in_month(CAL_GREGORIAN, $month, $year);
    $dates_month = array();
    for($index = 1 ; $index <= $num ; $index++)
    {
        $make_time = mktime(0,0,0,$month,$index,$year);
        $date = date("d-M-Y", $make_time);

        $date_day = date('D',$make_time); 
        if($date_day == $day_name)
        {
            $dates_month[$index] = $date;
            // $dates_month[$index]=$date.' day is -'.$date_day;
        }        
       
    }
    $_dates = array_values($dates_month);
    return $_dates; // return date  in array 
}

//  0 = Sunday,  1 = Monday,  2 = Tuesday,  3 = Wednesday, 4 = Thursday,  5 = Friday,  6 = Saturday

$function_month =  11; // pass your month
$function_year  =  2016; // pass your year 
// pass your day with number ex Sunday = 0
$function_day_in_number   =  0; // pass day in number of week  
$function_day   = "Mon"; // pass date in string like Mon, Tue etc..

$dates_of_month = dates_of_month($function_month ,$function_year,$function_day_in_number);
$dates_of_monthby_day = dates_of_monthby_day($function_month ,$function_year,$function_day);
echo "<pre> ";
print_r ( $dates_of_month ); // print list of all days
print_r ( $dates_of_monthby_day ); // print list of all days
echo " </pre> "; 

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  39  =  49

We accept paid advance and paid guest Posting on our Site : Contact US