Get date from monday and friday for the week by selecting month and year in php

Get date from monday and friday for the week by selecting month and yea in php. Is it possible?

Let me know if anybody didn’t understand my question.Thanks

Attached image is what I am looking for depending on month and year you choose…Thanks in advance…:slight_smile:

There would be 3 or 4 (or 5) mondays and fridays in a given month of a given year. Which are you looking for?

All the Mondays in given a month for specific year…I am not sure if you can see the image…

All Mondays in a Given Month:


$time = strtotime("first Monday of ".$monthname." ".$year); 
while($time <= strtotime("last Monday of ".$monthname." ".$year)) {
 echo date('jS',$time)." ".$monthname;
 $time += (7*24*60*60); //Advance One Week.
}

Thanks for the reply it did help but I wanted all the weeks in a month selected for that year Like Monday to Friday.

How are you defining a week-in-a-month? What if the month ends on a Wednesday? Do you want the Mon-Wed of that week too? Or the whole week? What about if it begins on a wednesday?

Yes that’s correct.Week is from Monday to Wednesday and in next month First week it will show from Thursday

So you want all weekdays in the month. Okay…

$time = strtotime("first day of ".$monthname." ".$year);
while($time <= strtotime("last day of ".$monthname." ".$year)) {
 if((date('w',$time) + 1) % 7 > 1) { //It's a weekday. 0 = Saturday, 1 = Sunday.
   echo date('jS',$time)." ".$monthname;
 }
 $time += (24*60*60); //Advance One Day
}

Thanks for your help