Forum

Thread tagged as: Question, Runway

Check dates match.

I have a "start date" and "end date" field in my collection. Both include the time. If the event starts and ends on the same date, but at a different time, I only want to show the "time" part of end_date (otherwise I want to show the full date.

Here's what I have

    <perch:content id="date" type="date" label="Start Date" format="%d %B %Y, %l:%M%p" time="true" required="true" />
    - 
    <perch:if match="eq" id="start_date" value="{end_date}" format="%d %B %Y">
        <perch:content id="end_date" type="date" label="End Date" format="%l:%M%p" time="true"  />
    <perch:else />
        <perch:content id="end_date" type="date" label="End Date" format="%d %B %Y, %l:%M%p" time="true"  />    
    </perch:if>

It doesn't seem to work as I'd like it to. Can you spot anything wrong in the conditionals?

Thanks for all your help - Perch support is amazing!

Paul Bell

Paul Bell 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You need to apply the formatting to both sides of the comparison:

<perch:if match="eq" id="start_date" value="{end_date}" format="%d %B %Y" format-both="true">

Thanks, Drew. That makes sense and is very neat. Unfortunately it's not working for me. Here's my modified template. It's included into all my other collection templates, but that shouldn't make a difference?

<p class="date">
    <perch:content id="date" type="date" label="Start Date" format="%d %B %Y, %l:%M%p" time="true" required="true" />
    - 
    <perch:if match="eq" id="start_date" value="{end_date}" format="%d %B %Y" format-both="true">
        <perch:content id="end_date" type="date" label="End Date" format="%l:%M%p" time="true"  />
    <perch:else />
        <perch:content id="end_date" type="date" label="End Date" format="%d %B %Y, %l:%M%p" time="true"  />    
    </perch:if>
</p>

It's always showing the full date (so, it's not picking up a match).

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you output both formatted, do you see a match?

Thanks, Drew - I've spotted the issue now - in my master template, the start date field only had the id of "date" not "start_date". Once corrected, this works perfectly. "format-both" would be a useful addition to the docs perhaps.