我怎样才能得到当周的星期一和星期五的日期?
我有以下代码,但如果当天是星期日或星期六,则会失败.
$current_day = date("N");
$days_to_friday = 5 - $current_day;
$days_from_monday = $current_day - 1;
$monday = date("Y-m-d", strtotime("- {$days_from_monday} Days"));
$friday = date("Y-m-d", strtotime("+ {$days_to_friday} Days"));
Run Code Online (Sandbox Code Playgroud) 我使用以下代码获取工作日的Ymd格式:
$monday = date('Y-m-d', strtotime('Monday'));
$tuesday = date('Y-m-d', strtotime('Tuesday'));
$wednesday = date('Y-m-d', strtotime('Wednesday'));
$thursday = date('Y-m-d', strtotime('Thursday'));
$friday = date('Y-m-d', strtotime('Friday'));
Run Code Online (Sandbox Code Playgroud)
今天是2012-08-01(第31周),我需要的周一价值应该是2012-07-30.
为什么strtotime('Monday')下周一会这样呢?