如何在php中找到给定日期的星期一到星期五的星期持续时间或星期范围。
for example i have date
$date = "2013-02-24";
现在我想要从一个月的星期一到星期五的日期范围
答案 0 :(得分: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"));
答案 1 :(得分: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');