I have a complete dates of the year, for example here is the code i took dates for complete year by passing particular day start date, end date , day and weekday as "2016-01-01","2016-12-31","Sunday", 0
PHP CODE:
$start_date = "2016-01-01";
$end_date = "2016-12-31";
$day = "Sunday";
//weekday: Sunday = 0 , Monday = 1 ..only if it is mulitple days
$dateArr = GetSelectdayDatesForCurYear($start_date, $end_date,$day, 0);
function GetSelectdayDatesForCurYear($start_date, $end_date, $selected_day, $weekday)
{
$seltd_weekdays = $selected_day; //even can supply multiple days like "Sunday,Monday,Friday..";
$arr_weekdays = explode(",", $seltd_weekdays);
$weekdaynum = $arr_weekdays[$weekday];
if(!$weekdaynum){ //if Sunday[0],Monday[1] not available
echo "Invalid Weekday!";
}
else
{
$get_start_date = strtotime("+0 day", strtotime($start_date) );
$get_end_date = strtotime($end_date);
$dateArr = array();
$get_date = strtotime($weekdaynum, $get_start_date); //first date for the first month
while($get_date <= $get_end_date) //loop till end date
{
$dateArr[] = date("Y-m-d", $get_date);
$get_date = strtotime("+1 weeks", $get_date);
}
$dateArr[] = date("Y-m-d", $get_date);
return $dateArr;
}
}
Here now i am trying to pass week no, example i need all the dates of sunday's for 1st week of complete year then i need the dates of first week or if i need 1st,3rd week, i need to get complete dates for 1,3 week, by above code i got complete dates for the year, how to get by week basics.
example i am trying to supply weeks number like this:
$for_the_weeks = "1,2"; //or "1,3,5" or "1,2,4"
How to make it out !!!