tags:

views:

57

answers:

2

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;
+1  A: 

could store it in an array with the day as the key and the +/-x days as the values.

Crayon Violent
very nice solution :)
Jascha
+3  A: 

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");
}
Artefacto
ahhh, love it. Very nice.
Jascha