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.

Conditional based on difference between entry time and current time

October 18, 2011 9:47am

Subscribe [2]
  • #1 / Oct 18, 2011 9:47am

    daithi

    38 posts

    I’m wondering if there is a way to use conditionals based on the relationship between an entry date and the current time?

    I would like to show a different date format depending on the age of an entry, for example:

    — For < 7 days ago / future entries 2.45pm January 12
    — For < 1 year ago January 12 2011
    — For > 1 year ago Winter 2010

    I know I can pull in the current time via php but is there a way to combine this with conditionals in order to change the display?

    Thanks for any help or pointers!
    David

  • #2 / Oct 18, 2011 8:04pm

    lebisol

    2234 posts

    See this http://ellislab.com/forums/viewthread/92848/
    or keep in mind that there is a variable {current_time} and format of choice for some of those native EE conditionals. Gets sticky with timestamp stored and all.

  • #3 / Nov 21, 2011 1:34pm

    daithi

    38 posts

    Thanks for the help — I wasn’t aware that {current_time} was available to me.

    I managed to get the effect that I was looking for using current_time and the Simple Math plugin (http://devot-ee.com/add-ons/simple-math)

    <!--Future Entries / Less than one week old-->
    {if {exp:simple_math calculate="{current_time format="%U"} - {entry_date format="%U"}"} <=604800}
     {entry_date format="%g.%i%a %F %j"}
    {/if}
    
    <!--More than one week old / Less than one year old-->
    {if {exp:simple_math calculate="{current_time format="%U"} - {entry_date format="%U"}"} >= 604801 AND {exp:simple_math calculate="{current_time format="%U"} - {entry_date format="%U"}"} <=31556926}
     {entry_date format="%F %j %Y"}
    {/if}
    
    <!--More than one year old -->
    {if {exp:simple_math calculate="{current_time format="%U"} - {entry_date format="%U"}"} >=31556926}
     {entry_date format="%F %Y"}
    {/if}

    A little messy but it does the job.

  • #4 / Nov 21, 2011 1:50pm

    lebisol

    2234 posts

    Cool, glad you made use of it and created a solution.

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

ExpressionEngine News!

#eecms, #events, #releases