Can anyone think of a better way of writing this out in a loop and getting the same result?
$today = date('l');
if($today == 'Wednesday'){
$min = date('l-m-d-y');
$max = date('l-m-d-y', strtotime('+4 days'));
}else if($today == 'Thursday'){
$min = date('l-m-d-y', strtotime('-1 days'));
$max = date('l-m-d-y', strtotime('+3 days'));
}else if($today == 'Friday'){
$min = date('l-m-d-y', strtotime('-2 days'));
$max = date('l-m-d-y', strtotime('+2 days'));
}else if($today == 'Saturday'){
$min = date('l-m-d-y', strtotime('-2 days'));
$max = date('l-m-d-y', strtotime('+1 days'));
}else if($today == 'Sunday'){
$min = date('l-m-d-y', strtotime('-3 days'));
$max = date('l-m-d-y');
}
echo $min . ' - ' . $max;
I assumed you wanted -3 in the min on Saturday and -4 on Sunday. Anyway, this is the idea:
$weekday = date("w");
if ($weekday == 0)
$weekday = 7;
if ($weekday >= 3) {
$min = date('l-m-d-y',
strtotime(($weekday==3?"+0":(3-$weekday))." days");
$max = date('l-m-d-y',
strtotime("+".(7-$weekday)." days");
}
could store it in an array with the day as the key and the +/-x days as the values.