根据结束日期,获取一周的日期列表

/*
根据结束日期,获取一周的日期列表
*/
function getWeekArr($startDate,$date)
{
    $weekArr    =    array();
    $w             =    date('w',strtotime($date));
    $w            =    $w==0 ? 7 : $w;
    for($i=0;$i<$w;$i++)
    {
            $weekDate    =    date('Y-m-d',strtotime($date)-$i*86400);
            if($weekDate>=$startDate)
            {
                $weekArr[]    =    $weekDate;
            }
    }
    return $weekArr;
}
$startDate    =    '2012-06-10';
$date        =    '2012-07-10';
$result        =    getWeekArr($startDate,$date);
var_dump($result);
/*
array
  0 => string '2012-07-10' (length=10)
  1 => string '2012-07-09' (length=10)
*/

Related posts:

Leave a Reply

Your email address will not be published.