如何在 PHP 的日期范围内获取所有星期的开始日期和结束日期?
周开始 = 周日,周末 = 周六
输入
$start_date='2013-02-01'
$end_date = '2013-02-28'
输出
开始日期='2013-02-01' 结束日期='2013-02-02'
开始日期='2013-02-03' 结束日期='2013-02-09'
开始日期='2013-02-10'结束日期 ='2013-02-16'
开始日期 ='2013-02-17' 结束日期 ='2013-02-23'
开始日期 ='2013-02-24' 结束日期 ='2013-02-28'
下面的代码返回给定日期的星期开始和结束
function getWeekDates($date)
{
$week = date('W', strtotime($date));
$year = date('Y', strtotime($date));
$from = date("Y-m-d", strtotime("{$year}-W{$week}-1")); //Returns the date of monday in week
$to = date("Y-m-d", strtotime("{$year}-W{$week}-7")); //Returns the date of sunday in week
echo "Start Date-->".$from."End Date -->".$to;//Output : Start Date-->2012-09-03 End Date-->2012-09-09
}
我怎样才能得到上面的结果?