I’m trying to list a few date ranges based off the last Tuesday which has past. What I was expecting was…
June 6 - June 12
May 30 - June5
But what I got was
June 6 - June 12
- December 24
My code is as follows
$lastWensE1 = date('F j', strtotime("last tuesday"));
$lastWensS1 = strtotime ( '-6 day' , strtotime ( $lastWensE1 ) ) ;
$lastWensE2 = strtotime ( '-7 day' , strtotime ( $lastWensE1 ) ) ;
$lastWensS2 = strtotime ( '-7 day' , strtotime ( $lastWensS1 ) ) ;
echo date('F j', $lastWensS1)." - ".$lastWensE1;
echo "<br/>";
echo date('F j', $lastWensS2)." - ".date('F j', $lastWensE2);
All the calculations of the past 3 Tuesdays should be done first, before trying to format the results, this gives clearer code:
This gives: