Forum
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!
You need to apply the formatting to both sides of the comparison:
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?
It's always showing the full date (so, it's not picking up a match).
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.