• Resolved Chris Gagner

    (@chrisgagner)


    I would like to be able to display a message every day, from 7am until 6pm. Is there a way to setup an IF statement to handle this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this:

    <?php
    // set your local timezone
    // http://www.php.net/manual/en/timezones.php
    date_default_timezone_set( 'Europe/Amsterdam' );
    
    $now = time();
    $seven_am = strtotime( '7 am' );
    $six_pm = strtotime( '6 pm' );
    
    if ( ( $seven_am <= $now ) && ( $six_pm >= $now ) ) {
    
    	// between 7am and 6pm
    	// your code here
    
    }
    ?>

    Change the timezone to yours in:

    date_default_timezone_set( 'Europe/Amsterdam' );

    http://www.php.net/manual/en/timezones.php

    Thread Starter Chris Gagner

    (@chrisgagner)

    Thanks. This works perfect.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘If Conditional – Time Range’ is closed to new replies.