phptime

PHP: Determine action based on time of day


I'm sure this is a pretty basic task, but I'm quite new to programming and am a bit confused.

Basically I want to execute a different action based on the time of day. For example, if the time is between 05:00 and 20:00 (8pm), run "scriptA". ELSE, or if time is between 20:00 and 05:00, run "scriptB".

What is the easiest way to do this? I basically want to run one script during the "Day" and the other at "Night".

Thank you!


Solution

  • <?php
    if((date("H") > 5) && (date("H")<20) )
    {
    
    //run_my_day_script
    
    }
    
    else
    {
    //run_my_evening_script
    
    }
    ?>