Answers.Body: <p>It looks like I figured it out by doing this:</p>
  
  <pre><code>.dateOrdered('and', '&gt;=' ~ startDate, '&lt;=' ~ endDate)
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-23T17:43:17.257Z
Answers.Text: If you want to include orders that were completed _on_ the end date, you can do `endDate|date_modify('+1 day')` :)
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-23T17:54:45.987Z
Answers.Text: Does it not take the time portion into account in the parameter? For end dates, I am passing strings like "2017-06-22 23:59:59".
Answers.UserDisplayName: Benjamin Kohl
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-23T18:10:33.287Z
Answers.Text: It does take the time into account, but only when you provide one – what you’re currently not doing! ;) `'>=' ~ startDate` returns a string ">=2017-06-02". You’d need to explicitly format the output using the `date` filter, e.g. `'>=' ~ startDate|date('c')` which would then output something like ">=2017-06-02T08:26+0800". If you prepend a `date_modify` filter you can do all sort of useful date and time calculations, see http://php.net/manual/en/datetime.formats.relative.php
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-23T18:15:40.837Z
Answers.Text: Sorry @Ben, I just noticed that I assumed `startDate` is a DateTime object in your code, which may not be the case at all.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-23T18:40:11.710Z
Answers.Text: We are getting the expected results now so I think we're all set. Thanks for the help!
Answers.UserDisplayName: Benjamin Kohl
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-23T17:38:43.607Z
Answers.LastActivityDate: 2017-06-23T17:38:43.607Z
Answers.UserDisplayName: Benjamin Kohl
Body: <p>I am attempting to get orders that were completed between two dates and the "before" and "after" criteria parameters don't seem to work. Perhaps I am using the wrong syntax? Example of how I am using them:</p>
  
  <pre><code>.after('2017-06-02 00:00:00')
  </code></pre>
  
Tags: <plugin-craftcommerce><datetime>
Title: How do I query for orders that were completed between two dates?
ThreadText: # How do I query for orders that were completed between two dates?
  
  (Asked by: username_0 on 2017-06-23)
  
  I am attempting to get orders that were completed between two dates and the "before" and "after" criteria parameters don't seem to work. Perhaps I am using the wrong syntax? Example of how I am using them:
  
  ```
  .after('2017-06-02 00:00:00')
  
  ```
  
  **Tags:** plugin-craftcommerce, datetime
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-06-23. Score: 2 | Accepted answer
  
  It looks like I figured it out by doing this:
  
  ```
  .dateOrdered('and', '>=' ~ startDate, '<=' ~ endDate)
  
  ```
  
  > **Comments:**
  > **username_1**: If you want to include orders that were completed _on_ the end date, you can do `endDate|date_modify('+1 day')` :)  
  > **username_0**: Does it not take the time portion into account in the parameter? For end dates, I am passing strings like "2017-06-22 23:59:59".  
  > **username_1**: It does take the time into account, but only when you provide one – what you’re currently not doing! ;) `'>=' ~ startDate` returns a string ">=2017-06-02". You’d need to explicitly format the output using the `date` filter, e.g. `'>=' ~ startDate|date('c')` which would then output something like ">=2017-06-02T08:26+0800". If you prepend a `date_modify` filter you can do all sort of useful date and time calculations, see http://php.net/manual/en/datetime.formats.relative.php  
  > **username_1**: Sorry @Ben, I just noticed that I assumed `startDate` is a DateTime object in your code, which may not be the case at all.  
  > **username_0**: We are getting the expected results now so I think we're all set. Thanks for the help!  
  
  ---
  
  