0

Need help to get this to work:

{if {current_time} >= {exp:str_to_time date="November 6th, {current_time format='%Y'}"} && {current_time} <= {exp:str_to_time date="January 7th, {current_time format='%Y'}"}}
6 Jan

{if:elseif {current_time} >= {exp:str_to_time date="January 6th, {current_time format='%Y'}"} && {current_time} <= {exp:str_to_time date="February 21st, {current_time format='%Y'}"}}
20 Feb

{if:elseif {current_time} >= {exp:str_to_time date="February 20th, {current_time format='%Y'}"} && {current_time} <= {exp:str_to_time date="March 28th, {current_time format='%Y'}"}}
27 Mar

{if:elseif {current_time} >= {exp:str_to_time date="March 27th, {current_time format='%Y'}"} && {current_time} <= {exp:str_to_time date="May 16th, {current_time format='%Y'}"}}
15 May

{if:elseif {current_time} >= {exp:str_to_time date="May 15th, {current_time format='%Y'}"} && {current_time} <= {exp:str_to_time date="August 4th, {current_time format='%Y'}"}}
3 Aug

{if:elseif {current_time} >= {exp:str_to_time date="August 3rd, {current_time format='%Y'}"} && {current_time} <= {exp:str_to_time date="September 12th, {current_time format='%Y'}"}}
11 Sept

{if:elseif {current_time} >= {exp:str_to_time date="September 11th, {current_time format='%Y'}"} && {current_time} <= {exp:str_to_time date="November 7th, {current_time format='%Y'}"}}
6 Nov
{/if}

2 Answers 2

0

You'll need to quote all of your plugin-generated variables inside your conditionals and remove the braces from current_time.

Also, I don't think you need all the elseif conditions - you should be able to do this with a series of if statements since they are all mutually-exclusive - that will read a little cleaner.

{if current_time >= '{exp:str_to_time date="November 6th, {current_time format='%Y'}"}' 
    && current_time <= '{exp:str_to_time date="January 7th, {current_time format='%Y'}"}'}
        6 Jan
{/if}

{if current_time >= '{exp:str_to_time date="January 6th, {current_time format='%Y'}"}' 
    && current_time <= '{exp:str_to_time date="February 21st, {current_time format='%Y'}"}'}
        20 Feb
{/if}

Etc.

2
  • Hi Derek, Thanks for reply but it doesn't work Im afraid. I need to be able to show for example 6th Jan if the current date is more than 6th Nov (Last year) and less than 7th Jan (current year)
    – Kippi
    Jan 4, 2016 at 17:33
  • I think I solved the problem with the (previous year) months by write the code like so: {if current_time >= '{exp:str_to_time date="November 5th, {current_time format='%y'} -1 year"}'
    – Kippi
    Jan 4, 2016 at 17:51
0

You may need to specify the format you are comparing against.

For example 'current_time' will look like

1454583625

so you need to make sure that

{exp:str_to_time date="November 6th, {current_time format='%Y'}"}

is outputting a number comparable to that

also sometimes I find wrapping my variables in quotes makes them work when they otherwise wouldn't

{if "{current_time}" >= "{exp:str_to_time date='November 6th, {current_time format='%Y'}'}" && "{current_time}" <= "{exp:str_to_time date='January 7th, {current_time format="%Y"}'}"}

you may also need to bracket your if statmnt

{if ("{current_time}" >= "{exp:str_to_time date='November 6th, {current_time format='%Y'}'}") && ("{current_time}" <= "{exp:str_to_time date='January 7th, {current_time format="%Y"}'}")}

also try

 {if ("{current_time}" >= "{exp:str_to_time date='November 6th, {current_time format='%Y'}'}") AND ("{current_time}" <= "{exp:str_to_time date='January 7th, {current_time format="%Y"}'}")}

but also conditions can be a little finicky with variables inside them so there is a plugin I use called ifElse on devotee

you may also find switchee helpful as it takes conditionals case by case, istead of checking EVERY if statment.

BUT also if your date is 'hardcoded' anyway could you not just make a timestring of that?

{if "{current_time format="%y%m%d"}" >= "{current_time format="%y"}1106"}

Edit Edit dammit this thread is soo old! why does stack exchange do that - put old threads to the top?

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.