All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

comparing months of start- and end dates with an if conditional to format output

Rene 11 Oct 2012 23:35 problem, complete

I would like to use two different output formats for events, depending if they cross over into another month or not:

Within a month 15. - 23. Nov
(Not showing the month for the start date)

Crossing over: 29. Nov - 3. Dec
(in this case, showing the month for start and end)

For this, I need to compare the month, and depending on if it's equal or different. I was experimenting retrieving the month with this tag {seminar_datum:start_date format='%M'} and comparing it with the same tag for the month of the end date with an {if ...} conditional, but I'm either getting PHP errors from EE about an invalid conditional, or end up comparing the tags instead of what's in the %M variable.

A pointer how to go about that would be helpful.

Regards, René

Replies

  1. Low 12 Oct 2012 06:51

    I've tested this in EE 2.5.3, and it worked:

    {if {event_dates:start_date format="%Y%m"} == {event_dates:end_date format="%Y%m"}} 
    same month
    {if:else}
    not same month
    {/if}


    Note that EE 2.5.2 had some issues with conditionals, so that might be the cause of PHP errors, too.

  2. Rene 12 Oct 2012 12:02

    Thank you, it didn't come to my mind to test for "%Y%m".

    Instead I've always used my desired output format "%M" for the comparison, and that wasn't robust.

    So looking for the string "%Y%m" made all the difference, problem solved!

  3. Low 12 Oct 2012 12:05

    Cool, good to hear.

  4. David M. Auble 21 Dec 2012 15:44

    I have a similar question -- I'm trying to compare two dates, where if the start date is not the same as the end date, then display the dates an event spans.

    So, something like this is what I have, but not working. Any ideas?

    {if {event:start_date} != {event:end_date}}{event:start_date format="%M %d"} - {event:end_date format="%M %d"}{/if}

    Thanks in advance!

  5. Low 21 Dec 2012 17:31

    You should be able to use the :one_day variable for that.

  6. David M. Auble 21 Dec 2012 18:52

    Perfect, I got it working.

    Thanks!

  7. Matt 14 Aug 2013 21:30

    I was wondering the same thing, and just posted on Stack Exchange when I couldn't get it working.

    I've tried adding the formatted start_date and end_date to a conditional both in quotes ('' OR "") and without quotes as you do in your example above. Neither works in my install of EE 2.5.5.

    Is there any other way to make this happen, or maybe a bug in Low Events 1.1.4 or EE 2.5.5?

  8. Low 15 Aug 2013 06:29

    To be on the safe side, I'd check for numerical values only, like 201308. Something like this:

    {if {event_dates:start_date format="%Y%m"} == {event_dates:end_date format="%Y%m"}}
    same month
    {if:else}
    not same month
    {/if}
    When debugging the advanced conditionals, try to remove them and add them one at a time to see which actual one is causing the trouble.

  9. Matt 15 Aug 2013 15:32

    Thanks!