<p>You could do this:</p>
<pre><code>{# Your date 2020-11 in atom format e.g 2020-11-01T00:00:00+01:00 #}
{% set departureDate = craft.app.request.getParam('departure') | date(&quot;Y-m&quot;) | atom %}

{# Your date + 1 month in atom format e.g 2020-12-01T00:00:00+01:00 #}
{% set untilDate = departureDate | date_modify('+1 month') | atom %}

{# Query between those 2 dates #}
{% set query = query.startsOn(['and','&gt;=' ~ departureDate, '&lt;' ~  untilDate ]) %}
</code></pre>
<p>Note that on the November the 25th for example, you'd only be querying 5 days of the month</p>

CC BY-SA 4.0
2020-11-26T15:20:31.263Z
Hey @oli ah ok, that's cool, that is what I did in the end, but it felt like maybe i could have been able to do it the way I hoped!!

Cheers!!
John
CC BY-SA 4.0
2020-11-26T14:40:11.190Z
2020-11-26T14:40:11.190Z
Oli
<p>You should be able to use the date string you get from your parametern without even editing it.</p>
<pre class="lang-php prettyprint-override"><code>{% set entries = entries.startsOn(craft.app.request.getParam('departure')) %}
</code></pre>
<p>More information about querying on datefields can be found here: <a href="https://craftcms.com/docs/3.x/date-time-fields.html#templating" rel="nofollow noreferrer">Date Fields | Craft CMS Documentation | 3.x</a></p>

CC BY-SA 4.0
2020-11-26T12:16:01.507Z
I'm specifically looking to do just the year and month, not the day as well!
John
CC BY-SA 4.0
2020-11-26T13:48:22.633Z
You could try to slice the date string to only display the year and month (`date|slice(0,7)`). I'm not sure if this would be a valid parameter. If not, you could try to use this as parameter: `['and', '>= date|slice(0,7)-01, '<= date|slice(0,7)-31']`
Joorren
CC BY-SA 4.0
2020-11-26T11:43:40.797Z
2020-11-26T11:43:40.797Z
Joorren
<p>I've got a date string from the url in this format: &quot;2021-06-01&quot; (year-month-day) and I want to find entries that have a date in the year and month from that string. The date is a date field in Craft.</p>
<pre><code>{% set entries = entries.startsOn(craft.app.request.getParam('departure')|date(&quot;Y-m&quot;)) %}
</code></pre>
<p>That does not work!</p>
<p>Any ideas gratefully received!</p>

<entries><datetime>
Convert string to date format that can be used in a craft.entries tag
# Convert string to date format that can be used in a craft.entries tag

(Asked by: username_0 on 2020-11-26)

I've got a date string from the url in this format: "2021-06-01" (year-month-day) and I want to find entries that have a date in the year and month from that string. The date is a date field in Craft.
{% set entries = entries.startsOn(craft.app.request.getParam('departure')|date("Y-m")) %}

That does not work!
Any ideas gratefully received!

**Tags:** entries, datetime


---

## 2 answers

### Answer by username_1 on 2020-11-26. Score: 2 | Accepted answer

You could do this:
{# Your date 2020-11 in atom format e.g 2020-11-01T00:00:00+01:00 #}
{% set departureDate = craft.app.request.getParam('departure') | date("Y-m") | atom %}

{# Your date + 1 month in atom format e.g 2020-12-01T00:00:00+01:00 #}
{% set untilDate = departureDate | date_modify('+1 month') | atom %}

{# Query between those 2 dates #}
{% set query = query.startsOn(['and','>=' ~ departureDate, '<' ~  untilDate ]) %}

Note that on the November the 25th for example, you'd only be querying 5 days of the month

> **Comments:**
> **username_0**: Hey @oli ah ok, that's cool, that is what I did in the end, but it felt like maybe i could have been able to do it the way I hoped!!  Cheers!!  

---

### Answer by username_2 on 2020-11-26. Score: 1

You should be able to use the date string you get from your parametern without even editing it.
{% set entries = entries.startsOn(craft.app.request.getParam('departure')) %}

More information about querying on datefields can be found here: Date Fields | Craft CMS Documentation | 3.x

> **Comments:**
> **username_0**: I'm specifically looking to do just the year and month, not the day as well!  
> **username_2**: You could try to slice the date string to only display the year and month (`date|slice(0,7)`). I'm not sure if this would be a valid parameter. If not, you could try to use this as parameter: `['and', '>= date|slice(0,7)-01, '<= date|slice(0,7)-31']`  

---

