how to get first and last day of the week in a given month using php

This question already has an answer here:

  • Get first day of week in PHP? 26 answers

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.

-------------Problems Reply------------

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;

}

Category:php Views:4 Time:2018-07-08
Tags: php

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.159 (s). 11 q(s)