Check Interval between time on a given day of the week

Asked

Viewed 50 times

0

Hello guys good night !

I am with this code in php working his function is to inform if the current time is in the range between 8 to 12

Good is working the problem and I need him to report only from Monday to Friday example: if it is Saturday ,or Sunday I do not want to display anything neither the if and neither the Else this would be possible ?

$hora = date('H');

if($hora >= "08" AND $hora < "12"){
   echo "OK";
}else{
   echo "Não ok..";
}

1 answer

1


Using one’s own date:

$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 it’s Sunday, if it’s 6 is Saturday, so just put your if and Else inside another if, as is using the sign of != (different) then will enter if it is different from Sunday and Saturday.

Obs: with numbers do not need quotes $hora >= "08", suffice $hora >= 08

  • 1

    Thanks buddy it worked out !

  • 1

    I put this variable $diadasemana in place of the $weekday worked !

  • You were very crafty @Hemersonprestes congratulations =) ... Sorry it was typo, now it’s fixed

Browser other questions tagged

You are not signed in. Login or sign up in order to post.