Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-26T15:20:31.263Z
Answers.Text: 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!!
Answers.UserDisplayName: John
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-26T14:40:11.190Z
Answers.LastActivityDate: 2020-11-26T14:40:11.190Z
Answers.UserDisplayName: Oli
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-26T12:16:01.507Z
Answers.Text: I'm specifically looking to do just the year and month, not the day as well!
Answers.UserDisplayName: John
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-26T13:48:22.633Z
Answers.Text: 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']`
Answers.UserDisplayName: Joorren
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-26T11:43:40.797Z
Answers.LastActivityDate: 2020-11-26T11:43:40.797Z
Answers.UserDisplayName: Joorren
Body: <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>
  
Tags: <entries><datetime>
Title: Convert string to date format that can be used in a craft.entries tag
ThreadText: # 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.
  
  ```php
  {% 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](https://craftcms.com/docs/3.x/date-time-fields.html#templating)
  
  > **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']`  
  
  ---
  
  