8

Is it possible to trigger a conditional in EE via the server time?

{if servertime == 'midnight to 13:00'}
      do this
{if:else}
      do something else
{/if}

Thank you

KSPR
  • 2,212
  • 4
  • 29
  • 46

4 Answers4

7

Sure, you can use the {current_time} global variable for basic conditionals. To use your example, here's how we'd check that the time's between midnight and 13:00:

{if
    '{current_time format="%H%i"}' >= '0000' AND
    '{current_time format="%H%i"}' <= '1300'
}
    It's between 00:00 and 13:00
{if:else}
    It isn't.
{/if}
Dom Stubbs
  • 1,198
  • 7
  • 15
4

If you're not opposed to using a little php in your template the user guide has a basic example to get you going: http://expressionengine.com/user_guide/modules/channel/channel_entries.html#start-on

There's also this plugin http://devot-ee.com/add-ons/cc-time-difference which may come in handy.

erwinheiser
  • 729
  • 5
  • 11
3

Just to reiterate what Jean said - if you are doing something like this, you need to make sure your DST (Day Light Saving) is appropriately configured.

If you're not using FocusLab Config - just drop the following into your config.php (in system/expressionengine/config/)

 $config['daylight_savings'] = ((bool) date('I')) ? 'y' : 'n';

That'll sort it for you dynamically.

madebyhippo
  • 681
  • 1
  • 5
  • 13
1

You'll need to watch your DST setup too. One way around this will be to use FocusLab's Master Config which fixes it so DST is handled automatically.

Jean St-Amand
  • 793
  • 5
  • 12