We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Comparing dates in IF statement

How Do I?

Trevzilla's avatar
Trevzilla
2 posts
4 years ago
Trevzilla's avatar Trevzilla

I’m trying to compare a date in an if statement. If “all day” is checked, the m/d/y of each date is the same, but the UTC timecode of the date is different. How to I compare just the m/d/y part to see if they are equal or not? Here is my code so far:

<div>
            {if "{calendar:event_first_date format='%m%d%Y'}" != "{calendar:event_last_date format='%m%d%Y'}"}
                <dt>Dates:</dt>
                <dd>{calendar:event_first_date format="%F %j, %Y"} - {calendar:event_last_date format="%F %j, %Y"}</dd>
                {if:else}
                <dt>Date:</dt>
                <dd>{calendar:event_first_date format="%F %j, %Y"}</dd>
             {/if}
</div>

This code isn’t working as only the else statement is being entered. Thanks for any help you can offer!

       
Andy McCormick's avatar
Andy McCormick
183 posts
4 years ago
Andy McCormick's avatar Andy McCormick

I would think that would work unless it doesn’t take the format into account when running the comparison. Have you tried outputting {calendar:event_first_date format='%m%d%Y'} {calendar:event_last_date format='%m%d%Y'} outside of the conditional to make sure what is being outputted is equal or not.

       
Andy McCormick's avatar
Andy McCormick
183 posts
4 years ago
Andy McCormick's avatar Andy McCormick

I just confirmed that this works as expected on my test site.

{if {date_1 format='%m%d%Y'} == {date_2 format='%m%d%Y'}}
  "they are the same"
 {if:else}
  "they are different"
 {/if}
       
Trevzilla's avatar
Trevzilla
2 posts
4 years ago
Trevzilla's avatar Trevzilla

Hmm, so strange. Thanks so much for your replies. Still no idea why it’s not working on my end. I’ve switched over to a different conditional that seems to be doing the trick. I think for some reason it’s my calendar add-on not doing what it’s supposed to be doing, or simply me being a complete noob with Expression Engine, so I don’t really know the ins and out of it yet.

Anyway, I’ve learned that the Add-on we’re using is the EE Calendar add-on by solspace.

https://docs.solspace.com/expressionengine/calendar/v3/templating/events.html#parameters

I’ve begun using the {if calendar:event_recurs} tag, and that seems to be getting me into the conditional just fine.

Maybe this is for another thread, but now I’m having issues getting all of my recurring dates to show. Just can’t seem to figure it out, and don’t really know if this is the right forum to ask that, or if I need to go to the calendar support page instead.

       
Andy McCormick's avatar
Andy McCormick
183 posts
4 years ago
Andy McCormick's avatar Andy McCormick

ok. I was going this with the native date fieldtype in EE. If you’re using Solspace Calendar, then you should definitely reach out to them. They’re good people and should be able to help you out.
You can also jump over to the EE Slack channel. There are a lot more people watching that who might be able to help you out: https://expressionengine.com/blog/join-us-in-slack#join-us-on-slack

       
Andy McCormick's avatar
Andy McCormick
183 posts
4 years ago
Andy McCormick's avatar Andy McCormick

We’re you ever able to get some resolution to this? I also saw where Solspace just released a new version of Calendar: https://twitter.com/solspace/status/1389619630294007812

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.