Answers.Body: <p>This is down to lacking documentation. Before/after are supposed to <a href="https://docs.craftcms.com/v3/element-query-params/entry-query-params.html" rel="nofollow noreferrer">take  "DateTime|string" as a parameter</a> in the ElementQuery. <strong>The format is not documented</strong>.</p>
  
  <p>Use "Y-m-d H:i:s"</p>
  
  <pre><code>{% set start = "2 months ago"|date("Y-m-d H:i:s") %}
  </code></pre>
  
  <hr>
  
  <p>Behind the scenes in building the query the CMS was replacing any dates I sent through with "2017-12-31 11:00:00" (no idea where this came from). After realising this I spelled out the before/after in format "Y-m-d H:i:s" and the dates started working.</p>
  
  <p><strong>Pixel and Tonic - Can you please update the docs to include the available date formats - or at least throw an error if it's not valid.</strong></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-04T22:31:20.757Z
Answers.Text: Noted @JamesNZ - Also worth mentioning the docs are in a public Github repo and pull requests are welcome. https://github.com/craftcms/docs
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-04T23:17:11.830Z
Answers.Text: Hey Brad. Oh of course - the only problem there is I don't know what the other valid date formats are. However if I can, I can I'll contribute back. Thanks.
Answers.UserDisplayName: JamesNZ
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-04T21:52:29.293Z
Answers.LastActivityDate: 2018-04-04T23:21:10.950Z
Answers.LastEditDate: 2018-04-04T23:21:10.950Z
Answers.UserDisplayName: JamesNZ
Body: <p>I have a Craft 3 site. For some reason the <strong>before</strong> filter isn't working when pulling entries from a channel, but <strong>after</strong> does. This is not a data issue.</p>
  
  <pre><code>{% set start = "2 months ago"|date() %}
  {% set end = "next week"|date() %}
  
  {% set listings = craft.entries({
      section: "tvListings",
      limit: null,
      with: "channel",
      before: end
  }).all() %}
  </code></pre>
  
  <p>For clarity the dates result in: </p>
  
  <ul>
  <li>Start: Feb 4, 2018</li>
  <li>End: Apr 9, 2018</li>
  </ul>
  
  <p>And one of the example entries is definitely in that date range (April 2nd).</p>
  
  <p><a href="https://i.sstatic.net/1dc9F.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/1dc9F.png" alt="enter image description here"></a></p>
  
  <p>If I ditch the "before" and go "after: start" it does work. If I try to say "give me all entries before Apr 9, 2018", the "Thunderbirds are go" (or any other listings) do not show.</p>
  
  <p>Surely I'm not doing something super stupid right?</p>
  
  <p>I'm running Craft 3.0.2.</p>
  
  <p>Thanks.</p>
  
  <hr>
  
  <p><strong>EDIT:</strong> I've started pulling apart the CMS to debug. EntryQuery->beforePrepare() builds the query that filters by date. Although the props before and after are set, once they're passed through Db::parseDateParam() it mutilates the dates and somehow comes out with "2017-12-31 11:00:00" for both - so no bloody wonder it's not working. If this is a date format thing for those props I'll update the answer. </p>
  
Tags: <entries><craft3><elementquery>
Title: Craft 3 entries "before" not working
ThreadText: # Craft 3 entries "before" not working
  
  (Asked by: username_0 on 2018-04-03)
  
  I have a Craft 3 site. For some reason the **before** filter isn't working when pulling entries from a channel, but **after** does. This is not a data issue.
  
  ```
  {% set start = "2 months ago"|date() %}
  {% set end = "next week"|date() %}
  
  {% set listings = craft.entries({
      section: "tvListings",
      limit: null,
      with: "channel",
      before: end
  }).all() %}
  
  ```
  
  For clarity the dates result in:
  
  * Start: Feb 4, 2018
  * End: Apr 9, 2018
  
  And one of the example entries is definitely in that date range (April 2nd).
  
  [![enter image description here](https://i.sstatic.net/1dc9F.png)](https://i.sstatic.net/1dc9F.png)
  
  If I ditch the "before" and go "after: start" it does work. If I try to say "give me all entries before Apr 9, 2018", the "Thunderbirds are go" (or any other listings) do not show.
  
  Surely I'm not doing something super stupid right?
  
  I'm running Craft 3.0.2.
  
  Thanks.
  
  ---
  
  **EDIT:** I've started pulling apart the CMS to debug. EntryQuery->beforePrepare() builds the query that filters by date. Although the props before and after are set, once they're passed through Db::parseDateParam() it mutilates the dates and somehow comes out with "2017-12-31 11:00:00" for both - so no bloody wonder it's not working. If this is a date format thing for those props I'll update the answer.
  
  **Tags:** entries, craft3, elementquery
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-04-04. Score: 2 | Accepted answer
  
  This is down to lacking documentation. Before/after are supposed to [take "DateTime|string" as a parameter](https://docs.craftcms.com/v3/element-query-params/entry-query-params.html) in the ElementQuery. **The format is not documented**.
  
  Use "Y-m-d H:i:s"
  
  ```
  {% set start = "2 months ago"|date("Y-m-d H:i:s") %}
  
  ```
  
  ---
  
  Behind the scenes in building the query the CMS was replacing any dates I sent through with "2017-12-31 11:00:00" (no idea where this came from). After realising this I spelled out the before/after in format "Y-m-d H:i:s" and the dates started working.
  
  **Pixel and Tonic - Can you please update the docs to include the available date formats - or at least throw an error if it's not valid.**
  
  > **Comments:**
  > **username_1**: Noted @username_0 - Also worth mentioning the docs are in a public Github repo and pull requests are welcome. https://github.com/craftcms/docs  
  > **username_0**: Hey username_1. Oh of course - the only problem there is I don't know what the other valid date formats are. However if I can, I can I'll contribute back. Thanks.  
  
  ---
  
  