0

does anyone know why this code will not display correctly? It looks right to me.

{if "{current_time format='%d.%m'}" >= "06.11" && "{current_time format='%d.%m'}" <= "07.01"}
6 Jan

{if:elseif "{current_time format='%d.%m'}" >= "06.01" && "{current_time format='%d.%m'}" <= "21.02"}
20 Feb

{if:elseif "{current_time format='%d.%m'}" >= "20.02" && "{current_time format='%d.%m'}" <= "28.03"}
27 Mar

{if:elseif "{current_time format='%d.%m'}" >= "27.03" && "{current_time format='%d.%m'}" <= "16.05"}
15 May

{if:elseif "{current_time format='%d.%m'}" >= "15.05" && "{current_time format='%d.%m'}" <= "04.08"}
3 Aug

{if:elseif "{current_time format='%d.%m'}" >= "03.08" && "{current_time format='%d.%m'}" <= "12.09"}
11 Sept

{if:elseif "{current_time format='%d.%m'}" >= "11.09" && "{current_time format='%d.%m'}" <= "07.11"}
6 Nov
{/if}

1 Answer 1

0

You are comparing numbers. {current_time format='%d.%m'} is outputted as 18.08. This number is bigger than 06.01 and smaller than 21.02. Therefor it is correct that the text 20 Feb is printed.

Use epoch dates to compare. It is a reliable solution.

Edit: The plugin Str To Time seems to have what you want. Use it to convert the date you want to compare to, to a timestamp. Something like this:

{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="August 3th, {current_time format='%Y'}"} && 
    {current_time} <= {exp:str_to_time date="September 9th, {current_time format='%Y'}"}}
11 Sept
{if:else}
No date available
{/if}
6
  • Hi Balloonatic. Thanks for the answer. Not sure what you mean by "epoch dates" Can you please elaborate with an example.
    – Kippi
    Commented Aug 18, 2015 at 9:16
  • Epoch is the number of seconds that have elapsed since January 1, 1970. You will get it if you use {current_time format="%U"}. This can be a usefull website: epochconverter.com Is the date comparing you want, the same for each year? Commented Aug 18, 2015 at 9:56
  • Yes, same for each year. I just want to compare day and month.
    – Kippi
    Commented Aug 18, 2015 at 10:56
  • I added a solution for your case. Commented Aug 19, 2015 at 6:28
  • Hi Balloonatic, That cracked it! Thanks so much for the assistance. Wonderful :)
    – Kippi
    Commented Aug 19, 2015 at 10:35

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.