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
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
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}
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.
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.
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.