Title: If Conditional &#8211; Time Range
Last modified: August 21, 2016

---

# If Conditional – Time Range

 *  Resolved [Chris Gagner](https://wordpress.org/support/users/chrisgagner/)
 * (@chrisgagner)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/if-conditional-time-range/)
 * 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](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/if-conditional-time-range/#post-4478389)
 * 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](http://www.php.net/manual/en/timezones.php)
 *  Thread Starter [Chris Gagner](https://wordpress.org/support/users/chrisgagner/)
 * (@chrisgagner)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/if-conditional-time-range/#post-4478449)
 * Thanks. This works perfect.

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

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Chris Gagner](https://wordpress.org/support/users/chrisgagner/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/if-conditional-time-range/#post-4478449)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
