2

I have 2 conditionals at the beginning of a template that are supposed to redirect the visitor to a different template if they are hitting the page outside of 2 different time spans, but the redirect is not working.

{if '{current_time format="%U"}' < '{start_date_1}' AND '{current_time format="%U"}' > '{end_date_1}'}{redirect="/closed"}{/if}
{if '{current_time format="%U"}' < '{start_date_2}' AND '{current_time format="%U"}' > '{end_date_2}'}{redirect="/closed"}{/if}

{start_date_1}, {start_date_2}, {end_date_1} & {end_date_2} are global variables.

Any help is appreciated.

3
  • 1
    Are the start date global variables in the same format as you're setting the current_time variables? Commented Sep 18, 2013 at 23:59
  • Yes, they are. I've even tried replacing the variables with the actual date values and it still doesn't work.
    – mediapimp
    Commented Sep 19, 2013 at 12:44
  • can you share the start date global variable value? As {current_time format="%U"} will be UNIX time so start_date_x and end_date_x should be in same. Commented Sep 19, 2013 at 13:08

1 Answer 1

3

your conditional doesn't make any sense. It's impossible for a number to be less and greater than an interval at the same time.

You need a OR, not an AND.

{if '{current_time format="%U"}' < '{start_date_1}' OR '{current_time format="%U"}' > '{end_date_1}'}{redirect="/closed"}{/if}
{if '{current_time format="%U"}' < '{start_date_2}' OR '{current_time format="%U"}' > '{end_date_2}'}{redirect="/closed"}{/if}
1
  • 1
    Duh. That was it! So obvious yet had me going in circles. Thanks!
    – mediapimp
    Commented Sep 19, 2013 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.