<p>String interpolation in Twig only works with double-quoted strings.</p>
<p>Change the <code>.startDate</code> line to <code>.startDate(['and', &quot;&gt;= #{start}&quot;, &quot;&lt; #{end}&quot;])</code> and it should work.</p>

CC BY-SA 4.0
2021-01-14T15:02:33.630Z
2021-01-14T15:02:33.630Z
Steve Rowling
<p>I'm trying to filter entries on the front end by a date range but no matter what I do I end up with no results, despite there being results in the, temporarily hard coded, date range I am using.</p>
<pre><code>
  {% set page = page ?? 1 %}
  {# set search parameter here #}
  {% set search = q ?? '' %}
  {# stage #}
  {% set stage = stage ?? '' %}
  {# date #}
  {% set start = now|date_modify('-16 week')|atom %}
  {% set end = now|date_modify('-1 week')|atom %}


  {% set entryQuery = craft.entries
    .section('projects')
    .limit(limit)
    .stage(stage)
    .startDate(['and', '&gt;= #{start}', '&lt; #{end}'])
    .search(search) %}
    
    {% for entry in entries %}
      {% include '_includes/project-listing-card' %}
    {% endfor %}

</code></pre>
<p>The code above sets some parameters based on the url and defaults. Without the <code>.startDate</code> line this outputs entries as expected. However once I add in the startDate (a date field) nothing gets output.</p>
<p>How do I output entries that are in the date range?</p>

CC BY-SA 4.0
2021-01-14T14:39:56.100Z
I think you need to use double quotes for string interpolation, so `">= #{start}"` and `"< #{end}"`.
Steve Rowling
CC BY-SA 4.0
2021-01-14T15:02:30.673Z
@SteveRowling that fixed it, if you make this an answer, I'll mark it correct
CreateSean
<templating><datetime>
Entries limited by date range
# Entries limited by date range

(Asked by: username_0 on 2021-01-14)

I'm trying to filter entries on the front end by a date range but no matter what I do I end up with no results, despite there being results in the, temporarily hard coded, date range I am using.

  {% set page = page ?? 1 %}
  {# set search parameter here #}
  {% set search = q ?? '' %}
  {# stage #}
  {% set stage = stage ?? '' %}
  {# date #}
  {% set start = now|date_modify('-16 week')|atom %}
  {% set end = now|date_modify('-1 week')|atom %}


  {% set entryQuery = craft.entries
    .section('projects')
    .limit(limit)
    .stage(stage)
    .startDate(['and', '>= #{start}', '< #{end}'])
    .search(search) %}
    
    {% for entry in entries %}
      {% include '_includes/project-listing-card' %}
    {% endfor %}


The code above sets some parameters based on the url and defaults. Without the .startDate line this outputs entries as expected. However once I add in the startDate (a date field) nothing gets output.
How do I output entries that are in the date range?

**Tags:** templating, datetime

> **Comments:**
> **username_1**: I think you need to use double quotes for string interpolation, so `">= #{start}"` and `"< #{end}"`.  
> **username_0**: @SteveRowling that fixed it, if you make this an answer, I'll mark it correct  

---

## 1 answers

### Answer by username_1 on 2021-01-14. Score: 3 | Accepted answer

String interpolation in Twig only works with double-quoted strings.

Change the `.startDate` line to `.startDate(['and', ">= #{start}", "< #{end}"])` and it should work.


---

