Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conditional based on time

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

like image 598
KSPR Avatar asked Nov 05 '12 08:11

KSPR


2 Answers

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}
like image 120
Dom Stubbs Avatar answered Sep 29 '22 13:09

Dom Stubbs


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.

like image 24
erwinheiser Avatar answered Sep 29 '22 11:09

erwinheiser