Forum

Thread tagged as: Question

How do I filter somewhere between two dates?

Does anyone have a good solution to filtering somewhere between two dates in a template?

Something like this: <perch:if id="{today}" match="eqbetween" value="start_date, end_date" format="Y-m-d" format-both="true"> (Does not work).

Thanks. Stig

Stig Tafto

Stig Tafto 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What are start_date and end_date ? Those strings aren't dates.

start_date and end_date is from another template, see below.

<perch:content id="start_date" type="date" label="Kampanjestart" format="Y-m-d" time="false" allowempty="false" divider-before="Start og stopp dato for kampanjen"/> -  
<perch:content id="end_date" type="date" label="Kampanjeslutt" format="Y-m-d" time="false" allowempty="false"/> 

S

Like this:

template_one.html:

<p class="date"> 
    <perch:content id="startDate" type="date" label="Kampanjestart" format="Y-m-d" time="false" allowempty="false" divider-before="Start og stopp dato for kampanjen"/> -  
    <perch:content id="endDate" type="date" label="Kampanjeslutt" format="Y-m-d" time="false" allowempty="false"/> 
</p>

template_two.html:

<section id="intro">
<perch:template path="content/template_one.html" />
</section>
<perch:if id="{today}" match="eqbetween" value="startDate, endDate" format="Y-m-d" format-both="true">

s

Duncan Revell

Duncan Revell 78 points
Registered Developer

I assume today is being passed into template_two as a variable?

You can't use {...} for the id name, only the value, so what you want would look like:

<perch:if id="today" match="eqbetween" value="{startDate}, {endDate}" format="Y-m-d" format-both="true">

However, I don't think that is going to work, so you will need to do:

<perch:if id="today" match="gt" value="{startDate}" format="Y-m-d" format-both="true">
<perch:if id="today" match="lt" value="{endDate}" format="Y-m-d" format-both="true">
...template stuff...
</perch:if>
</perch:if>

Perfect. Thank you!