I want to design a PHP script for determine list of all the Monday of the month.
For December - 2014 (1-12-2014, 8-12-2014, 15-12-2014, 22-12-2014, 29-12-2014) and
For January - 2015 (29-12-2014, 5-1-2015, 12-1-2015, 19-1-2015, 26-1-2015)
For February - 2015 (2-2-2015,9-2-2015,16-2-2015,23-2-2015)
For November - 2014 (27-10-2014,3-11-2014,10-11-2014,17-11-2014,24-11-2014,)
In Script if the first day of the month is middle of the week than it should count the last month Monday.
In this script week starts from Monday to Sunday.
Ans :
<?php
$selectedmonth="January 2015";
$dat=strtotime("first day of ".$selectedmonth);
if(date('N',$dat)>1) {
$previousmonth=date('F Y',strtotime($selectedmonth."-1 month"));
$firstMonday=strtotime("last monday of ".$previousmonth);
}
else
{
$firstMonday=strtotime("first monday of ".$selectedmonth);
}
$temp=$firstMonday;
$s="(".date("Y-m-d",$firstMonday).",";
$lastmonday=strtotime("last monday of ".$selectedmonth);
while($temp!=$lastmonday)
{
$temp=strtotime(date("d F Y",$temp)."+1 week");
$s.=date("Y-m-d",$temp).",";
}
$s=trim($s,",").")";
echo $s;
?>
Thanks All of you.