ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Comparing current_time to date range?

December 09, 2010 6:49am

Subscribe [2]
  • #1 / Dec 09, 2010 6:49am

    LucPestille

    146 posts

    I need to time some template changes (not channel entires, otherwise this would be a breeze) to change during a date range, but can’t see how to do it. Does anyone know of a way (preferably without resorting to .php) to do the following, either with native code, or a (2.0) plugin?

    Show embed1 between 1st Dec and 4th Jan;

    {if "{current_time format='%m/%d'}" >= "12/01" AND "{current_time format='%m/%d'}" <= "01/04" }
        {embed="embeds/christmas_opening_hours"}
    {if:else}
        {embed="embeds/random_store"}
    {/if}

    Logically, i think that should work, but it doesn’t. One date comparison works, but spanning across two doesn’t…

    Thanks,

  • #2 / Dec 09, 2010 7:05am

    LucPestille

    146 posts

    I managed to do this a different way, comparing the %z (day of the year) value that date formatting gives;

    {if "{current_time format='%z'}" >= "335" OR "{current_time format='%z'}" <= "4" }

    It’s an inelegant way to do it, but does work - a plugin for comparing dates would still be useful…

  • #3 / Dec 09, 2010 7:18am

    Max Lazar

    341 posts

    {if {current_time format='%m%d'} >= 1201 OR {current_time format='%m%d'} <= 0104 }
        Christmas time! 
    {if:else}
        Jast another day… 
    {/if}

    one more example (but it’s only for 2010/2011 years)

    {if {current_time format='%m%d'} >= 1201 OR {current_time format='%m/%d'} <= 0104 }
        Christmas time!
    {if:else}
        Jast another day…
    {/if}
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases