0

how to get first and last day of the week in a given month using php . I tried to get the answer by googling but un-abale to get it . Please help me any body . I will be gr8 for him.

  • for the last day http://stackoverflow.com/questions/1686724/how-to-find-the-last-day-of-the-month-from-date – Kevin May 22 '15 at 04:11

1 Answers1

0

Hi every body some how i got solution and it is given below.

$fstSunday = date("d-F-Y", strtotime("first Sunday of ".date('M')." ".date('Y')."")); $weekArray = getfstlastdayOfWeekofmonth($fstSunday); echo '

';
                print_r( $weekArray);

    function getfstlastdayOfWeekofmonth($paramFstSundayofMonth)
    {

        $fstSunday = $paramFstSundayofMonth;

        //echo 'last date of the week-'.$oneWeekLater = date('d-m-Y', strtotime('+1 week',strtotime($fstSunday)));
        $countMnth  =  date("t",strtotime($fstSunday));
        $dayOfmonth =  date("d",strtotime($fstSunday));

        if($countMnth==31 && $dayOfmonth <= 3) 
        $countmonth  = 5;
        else
        $countmonth  = 4;

        $weekArray = array();   

        for($i=0;$i<$countmonth;$i++)
        {
            $oneWeekLater = date('d-F-Y', strtotime('+1 week',strtotime($fstSunday)-1));

            $weekArray[] =  array('fstdayWeekOfmonth'=> $fstSunday,'lastDayWeekOfmonth'=>$oneWeekLater)  ;

            $fstSunday = date('d-F-Y', strtotime('+1 week',strtotime($fstSunday)));

        }
    //  echo '<pre>';

        return $weekArray;

    }