This will do Saturdays:
Code: Select all
for($i=-1, $next=strtotime('-1 day', strtotime($digest_date)); $next<=strtotime($todaysdate); $i++, $next=strtotime('next Saturday', $next));
echo $i;
It is better to use time() if it will always be todays date:
Code: Select all
for($i=-1, $next=strtotime('-1 day', strtotime($digest_date)); $next<=time(); $i++, $next=strtotime('next Saturday', $next));
echo $i;
And you could strtotime() before the loop for the $digest_date:
Code: Select all
$start = strtotime($digest_date);
for($i=-1, $next=strtotime('-1 day', $start); $next<=time(); $i++, $next=strtotime('next Saturday', $next));
echo $i;
Maybe a function:
Code: Select all
function days_between($day, $start, $stop=null) {
if(empty($stop)) {
$stop = time();
}
if(!is_int($start) && !($start = strtotime($start))) {
return false;
}
if(!is_int($stop) && !($stop = strtotime($stop))) {
return false;
}
for($i=-1, $next=strtotime("previous $day",$start); $next<=$stop; $i++, $next=strtotime("next $day", $next));
return $i;
}
echo days_between('Thursday', '2010-04-08', '2010-04-15');