Reputation: 40653
Is there an easy way to get last week's, say, Monday? If today is Tuesday, I do not want yesterday's Monday. Rather, I want the Monday 8 days ago (last week's Monday). Then I want that Monday's proceeding Sunday. Basically, I'm trying to get the date range for last week, Monday to Sunday.
This doesn't always work right:
date('Y-m-d', strtotime('last Monday')
Suggestions?
Upvotes: 0
Views: 336
Reputation: 11689
You can use “this week” format:
$monday = strtotime( 'this week', strtotime( '7 days ago' ) );
$sunday = strtotime( '+ 6 days', $monday );
“this_week” returns monday of previous week, then — adding 6 days — you obtain the monday of relative week.
Upvotes: 3
Reputation: 475
The strtotime
function accepts the current date as a parameter.
http://php.net/manual/en/function.strtotime.php
Just pass in strtotime('last Sunday')
as the parameter to get a weekday of the last full week.
$beginning_of_week = strtotime('last Sunday');
$result = date('Y-m-d', strtotime('last Monday', $beginning_of_week));
echo $result;
Upvotes: 1