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.

Looking for advice on how to compare three dates, display only most current

May 31, 2012 7:21pm

Subscribe [1]
  • #1 / May 31, 2012 7:21pm

    John St-Amand

    865 posts

    Hi all:

    I know I could write a series of conditionals for this one, but that strikes me as inefficient.  Here’s the scoop. I have three custom fields that are date fields.  I need to display ONLY the one that is most current.  So can someone recommend a way for me to do this?  With date format set to %Y%m%j it would be easy to see which of the three is the largest - but how to I efficiently do the comparison?

    {If date1 > date2 AND date1 > date3}display date1{/if}
    {if date2 > date1 AND date 2 > date3}display date 2{/if}
    {if date3 > date1 AND date3 > date2}display date3{/if}

    Is that really my only native option without using PHP?  What approach would you recommend?

  • #2 / May 31, 2012 8:59pm

    Bhashkar Yadav

    727 posts

    Hi John,

    You can find current one date among 3 dates by using

    {if date1 > date2 AND date2 > date3}
     {date1 format="%Y%m%j"}
    {if:elseif date2 > date3}
     {date2 format="%Y%m%j"}
    {if:else}
     {date3 format="%Y%m%j"}
    {/if}

    Hope this would help you.


    Best Regards,

  • #3 / May 31, 2012 9:12pm

    John St-Amand

    865 posts

    Thanks, Bhashkar.  My principal concern is that i then have to run the resulting date through Made by Hippo’s multi language date converted - which parses earlier than the conditionals.  So i may have no choice but to use PHP or perhaps the query module to do the comparison in such a way that it parses a bit earlier.  Thanks for the message though - I’d just like to find a way to do the comparison without reporting to complex conditionals if i can avoid them.

  • #4 / May 31, 2012 9:32pm

    Bhashkar Yadav

    727 posts

    Hi John,

    I think, use of query module would be better as you can find recent date with a single query and it wouldn’t have parsing issue as you mentioned.

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

ExpressionEngine News!

#eecms, #events, #releases