复杂点的:
$present = date('y-m-d',time());//当前日期
$first = 1;//第一天为周一则为1,第一天为周末为0
$w = date("w",strtotime($present)) ? date("w",strtotime($present)) - $first : 6;
//获取本周开始日期,如果$w是0,则表示周日,减去 6 天
$week_start = date('Y-m-d', strtotime("$present-$w"."days"));
//本周结束日期
$week_end = date('Y-m-d', strtotime("$week_start +6 days"));
简单的:
$nowWeekFirstDay = date('Y-m-d', strtotime('this week Monday'));
$nowWeekLastDay = date('Y-m-d', strtotime('this week Sunday'));
上周第一天和最后一天
$lastWeekFirstDay = date('Y-m-d', strtotime('last week monday'));
$lastWeekLastDay = date('Y-m-d', strtotime('last week sunday'));
两种方式获取当月第一天及最后一天
第一种:
$firstDay = date('Y-m-01', strtotime($date));
$lastDay = date('Y-m-d', strtotime(date('Y-m-01', strtotime($date)). ' 1 month -1 day'));
第二种:
$firstDay = date('Y-m-01', strtotime($date));
$lastDay = date('Y-m-d', strtotime("$firstDay +1 month -1 day"));