4

如何在php中查找给定日期从周一到周五的周持续时间或周范围。

for example i have date
$date = "2013-02-24";

现在我想要这个月从星期一到星期五的日期范围

4

2 回答 2

1

试试这个答案。

 $date = "2013-02-24";
 $week =  date('W', strtotime($date));
 $year =  date('o', strtotime($date));
 echo "first day of week". $from = date("Y-m-d", strtotime("{$year}-W{$week}-1")); 
 echo "end day of week". $to = date("Y-m-d", strtotime("{$year}-W{$week}-5")); 
于 2013-11-15T08:48:16.173 回答
0
function week_range($date) {
    $ts = strtotime($date);
    $start = (date('w', $ts) == 0) ? $ts : strtotime('last monday', $ts);
    return array(date('Y-m-d', $start),
                 date('Y-m-d', strtotime('next friday', $start)));
}

并这样称呼它:

list($start_date, $end_date) = week_range('2009-05-10');
于 2013-11-15T08:49:54.967 回答