note 84543 deleted from function.date by derick

From: Date: Sun, 26 Oct 2008 13:00:06 +0000
Subject: note 84543 deleted from function.date by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-145770@lists.php.net to get a copy of this message
Note Submitter: gertrude dot mendoza at gmail dot com ---- <?php /* @params $firstdate, $lastdate @return array() of array(monday,sunday) @description returns all the mondays and sundays of the given date range */ function get_week_intervals($fdate,$ldate) { list($year,$month,$day) = explode('-',$fdate); $daynum = date('w', mktime(date('H'), date('i'), date('s'), $month, $day, $year) ); $daynum = $daynum==0? 7 : $daynum; $week=array(); //get the dayname of the first day //if month = current month get the current date as the last day if($month==date('m')) { $lastday = date('d'); } else { $lastday = date('t', strtotime($fdate)); } if((date('l',strtotime($fdate))) == 'Sunday') { $monday = $fdate; $sunday = $fdate; } else { $monday = $fdate; $sunday = date('Y-m-d',(mktime(date('H'), date('i'),date('s'),$month, $day,$year))-($daynum-7)*86400); } $week[] = array('monday'=>$monday,'sunday'=>$sunday); $day = date('d',strtotime($sunday." +1 day")); while($sunday < $ldate) { $monday = date('Y-m-d',strtotime($sunday." +1 day")); list($year,$month,$day) = explode('-',$monday); $daynum = date('w', mktime(date('H'), date('i'), date('s'), $month, $day, $year) ); $daynum = $daynum==0? 7 : $daynum; $sunday = date('Y-m-d',(mktime(date('H'),date('i'), date('s'),$month,$day,$year))-($daynum-7)*86400); if($sunday > $ldate) { $sunday = $ldate; } $week[] = array('monday'=>$monday,'sunday'=>$sunday); } return $week; } ?>

« previous php.notes (#145770) next »