-1 Monday output is this Monday time, very strange
Reply content:
-1 Monday output is this Monday time, very strange
Because the foreigner thinks "this Monday" is next Monday, "Last Monday" is this Monday
Just "-2 Monday", or "Monday last week"?
Date (' y-m-d ', strtotime ('-'). (6+date (' W ')). ' days '));
-7 days
last week
Usually in two steps, get the last week of any day, and then go to the Monday, like the end of the month is to find the next 1th, and then 1 days.
Let's write a generic approach to this.
function last_monday($timestamp=0,$is_return_timestamp=true){ static $cache ; $id = $timestamp.$is_return_timestamp; if(!isset($cache[$id])){ if(!$timestamp) $timestamp = time(); $thismonday = this_monday($timestamp) - /*7*86400*/604800; if($is_return_timestamp){ $cache[$id] = $thismonday; }else{ $cache[$id] = date('Y-m-d',$thismonday); } } return $cache[$id]; }
Date (' W ') gets the current week, since Monday to Saturday is 1-6, Sunday is 0. When the value was 0, the last Monday was 13 days ago. The rest is date (' W ') + 6 days ago.
$days = date('w')==0?13:date('w')+6;echo date('Y-m-d',time()-$days*86400);
Here you see the document link description
echo "Previous Monday:". Date ("Y-m-d", Strtotime ("Last Monday")). "
";
$time = Strtotime ("-7 Day");
$timetest =date ("y-m-d h:i:sa", $time);