note 84543 added to function.date
| From: | gertrude dot mendoza at gmail dot com | Date: | Fri, 18 Jul 2008 07:41:46 +0000 |
| Subject: | note 84543 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-141650@lists.php.net to get a copy of this message | ||
/*
@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;
}
----
Server IP: 202.79.178.90
Probable Submitter: 202.52.76.99
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/84543
Del: integrated -- https://master.php.net/note/delete/84543/integrated
Del: useless -- https://master.php.net/note/delete/84543/useless
Del: bad code -- https://master.php.net/note/delete/84543/bad+code
Del: spam -- https://master.php.net/note/delete/84543/spam
Del: non-english -- https://master.php.net/note/delete/84543/non-english
Del: in docs -- https://master.php.net/note/delete/84543/in+docs
Del: other reasons-- https://master.php.net/note/delete/84543
Reject -- https://master.php.net/note/reject/84543
Search -- https://master.php.net/manage/user-notes.php