Check Interval between time on a given day of the week

0

Hello people, good evening!

I have this code in php working its function is to inform if the current time is in the range of 8 to 12

Well, the problem is working and I need it to report only from second to sixth example: if it is Saturday, or Sunday, I do not want to display anything, neither the if nor the else would be possible?

$hora = date('H');

if($hora >= "08" AND $hora < "12"){
   echo "OK";
}else{
   echo "Não ok..";
}
    
asked by anonymous 22.03.2017 / 06:27

1 answer

1

Using date itself:

$diadasemana = date('w');

if ($diadasemana != 0 AND $diadasemana != 6) {
    $hora = date('H');
    if ($hora >= 08 AND $hora < 12) {
        echo "OK";
    } else {
        echo "Não ok..";
    }
}

If it is 0 is Sunday, if it is 6 is Saturday, then just put your if and else inside another if, as it is using the != sign (different) then it will enter if if different from Sunday and Saturday.

  

obs: with numbers you do not need quotation marks $hora >= "08" , just $hora >= 08

    
22.03.2017 / 06:32