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.

  • 1
    Are the start date global variables in the same format as you're setting the current_time variables? – Romans-8---31-39 Sep 18 '13 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 Sep 19 '13 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. – Bhashkar Yadav Sep 19 '13 at 13:08
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}
| improve this answer | |
  • 1
    Duh. That was it! So obvious yet had me going in circles. Thanks! – mediapimp Sep 19 '13 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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