$uFrom = 1340348400; $uTo = 1340409600; $time = 1340310456; $bWork = ($uFrom <= $time and $uTo > $time) ? 1 : 0; 

We get 0. Why is this happening?

    2 answers 2

    Probably because just $uFrom > $time =)

     $bWork = ($uFrom <= $time && $uTo > $time) ? 1 : 0; 

    This construction assigns a unit if ($uFrom <= $time && $uTo > $time)==true , and this construction in turn returns true only if both conditions are is true . In your case, this does not happen. You get that !($uFrom <= $time)==true , i.e. ($uFrom > $time)==true . You should use or , however, it already depends on your task.

    UPD:

     $c = 7; // date("H"); текущее время(в часах) for($i=1;$i<=24;$i++) // вот демонстрация для каждого часа { echo $i." => "; if($i < 4 || $i > 11) print("Open!"); else print("Close"); echo("<br>"); } 

    Finish the algorithm to the mind or write the opposite (determine when closed), I think you will not be difficult.

    • For example, opening at 11 am, closing at 4 am. It is one in the morning, and the object is closed. Because at mktime the hour of the night is less than 11 am. - Tchort
    • Well, that's right! --- And you need to determine whether the object is closed? - AseN
    • Yes, at one in the morning, he should be open to ideas. If it works from 11 am to 4 am - Tchort
    • For example, if you write: echo "C" .date ("H: i: s", $ uFrom). "<br />"; echo "Now" .date ("H: i: s", $ uTime). "<br />"; echo "By" .date ("H: i: s", $ uTo). "<br /> <br />"; That will return From 11:00:00 Now 03:00:00 By 04:00:00 - Tchort
    • Completed the answer. - AseN

    $uFrom > $time 1340348400 > 1340310456