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.

If Else for dates

December 13, 2010 8:33pm

Subscribe [3]
  • #1 / Dec 13, 2010 8:33pm

    grrramps

    2219 posts

    For a section on an EE site I want to display entry dates but only for the past year, hiding the date for previous years. How do I do that?

    Is it something like this?

    {if "{current_time format='%z'}" == "{entry_date format='%z'}"}
    {date_heading}
    {!--<div class="date">{entry_date format="%l, %F %j, %Y"}</div>--}
    {/date_heading}
    {if:else}
    {date_heading}
    <div class="date">{entry_date format="%l, %F %j, %Y"}</div>
    {/date_heading}
    {/if}

    What would be the entry date format for specific years?

  • #2 / Dec 14, 2010 9:17am

    Sue Crocker

    26054 posts

    Hi, grramps.

    See: http://ellislab.com/expressionengine/user-guide/templates/date_variable_formatting.html

    Use %Y for your year testing. Does that help?

  • #3 / Dec 14, 2010 12:23pm

    grrramps

    2219 posts

    Hi, grramps.

    See: http://ellislab.com/expressionengine/user-guide/templates/date_variable_formatting.html

    Use %Y for your year testing. Does that help?

    Sue, thanks. It does for the year but not for the year of the entry (duh). I simply changed it to the entry_id and that worked perfectly. Is there tag code for the entry date or entry year?

  • #4 / Dec 14, 2010 6:00pm

    Ingmar

    29245 posts

    Is there tag code for the entry date or entry year?

    I’m afraid I don’t understand. You want to display the year only for entries not from the current year, is that it?

    {if "{entry_date format='%Y'}" == "{current_time format='%Y'}" }
  • #5 / Dec 14, 2010 6:17pm

    grrramps

    2219 posts

    I want to avoid displaying the date for all entries before a certain year. For example, entries from 2009 and 2010 would display a date, but entries prior to 2009 would simply be blank.

    How would that work?

  • #6 / Dec 15, 2010 9:45am

    Sue Crocker

    26054 posts

    What about when 2011 rolls around… do you need to just display 2010 and 2011? In other words, is it the current year and one year previous, or is is anything before the fixed year of 2009?

  • #7 / Dec 15, 2010 12:30pm

    grrramps

    2219 posts

    What about when 2011 rolls around… do you need to just display 2010 and 2011? In other words, is it the current year and one year previous, or is is anything before the fixed year of 2009?

    Sue, anything before the fixed year of 2009. Doable? Or, is it better to stick with entry_id?

  • #8 / Dec 15, 2010 3:45pm

    jcollinsmedia

    25 posts

    To keep this in EE syntax try using “%U” for the time formatting. Then you could determine the seconds for your cut-off point(s) and write conditions from there.

  • #9 / Dec 15, 2010 3:58pm

    Ingmar

    29245 posts

    I actually disagree with jcollinsmedia here, all we need is the year, let’s make PHP do the work. Unless I am misunderstanding you, wouldn’t that work?

    {if "{entry_date format='%Y'}" > 2008} 
       {entry_date format="%l, %F %j, %Y"}
    {/if}
  • #10 / Dec 15, 2010 4:02pm

    grrramps

    2219 posts

    I actually disagree with jcollinsmedia here, all we need is the year, let’s make PHP do the work. Unless I am misunderstanding you, wouldn’t that work?

    {if "{entry_date format='%Y'}" > 2008} 
       {entry_date format="%l, %F %j, %Y"}
    {/if}

    I like this one better. It’s not as precise as the entry_id, of course, but quickly usable.

    Thanks, Ingmar.

  • #11 / Dec 15, 2010 4:17pm

    jcollinsmedia

    25 posts

    @Ingmar Greil: You’re fired!
    I agree with your suggestion.  😊  Thanks!

  • #12 / Dec 15, 2010 5:00pm

    Ingmar

    29245 posts

    Woot! So let’s clear that one out. Post again in case there’s anything else, please.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases