Answers.Body: <p>Something like this should work:</p>
  
  <pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
  $criteria-&gt;section  = 'sectionHandle';
  $criteria-&gt;postDate = array('and', '&gt; 2014-11-03 23:59:59', '&lt; 2014-11-05 00:00:00');
  $results = $criteria-&gt;find();
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-19T17:51:31.927Z
Answers.Text: This works great Brad. Is there any way I can make it just by the date and not include the time? I tried yii-syntax with **postDate = ['IN', '2014-11-04']** but that got me a "Fatal error: Call to a member function getTimestamp() on a non-object in /craft/app/helpers/DbHelper.php on line 597". Any ideas?
Answers.UserDisplayName: naboovalley
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-19T17:56:04.753Z
Answers.Text: Nothing I can think of...
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-19T18:00:50.087Z
Answers.Text: Is there another way you would recommend me fetching elements from a section posted at a specific date using Craft build in API functions?
Answers.UserDisplayName: naboovalley
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-19T22:26:12.663Z
Answers.Text: Not without directly querying the database.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-19T17:13:54.013Z
Answers.LastActivityDate: 2015-03-19T17:13:54.013Z
Answers.UserDisplayName: Brad Bell
Body: <p>I'm trying to get elements in a section created on a specific date. How do I do that?</p>
  
  <p>This is what I've been trying with:</p>
  
  <pre><code>$criteria               = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
  $criteria-&gt;section  = 'sectionHandle';
  $criteria-&gt;postDate     = '2014-11-04';
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-10-26T00:06:59.620Z
Comments.Text: Can anyone suggest an update to the accepted answer that works in Craft 4? I'm getting errors to the effect of "Class "modules\modulename\services\ElementType" not found'.
Comments.UserDisplayName: Jason McKinney
Tags: <plugin-development><elementcriteriamodel>
Title: How do I get elements using getCriteria from a specific date?
ThreadText: # How do I get elements using getCriteria from a specific date?
  
  (Asked by: username_0 on 2015-03-19)
  
  I'm trying to get elements in a section created on a specific date. How do I do that?
  
  This is what I've been trying with:
  
  ```
  $criteria               = craft()->elements->getCriteria(ElementType::Entry);
  $criteria->section  = 'sectionHandle';
  $criteria->postDate     = '2014-11-04';
  
  ```
  
  **Tags:** plugin-development, elementcriteriamodel
  
  > **Comments:**
  > **username_1**: Can anyone suggest an update to the accepted answer that works in Craft 4? I'm getting errors to the effect of "Class "modules\modulename\services\ElementType" not found'.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-03-19. Score: 9 | Accepted answer
  
  Something like this should work:
  
  ```
  $criteria = craft()->elements->getCriteria(ElementType::Entry);
  $criteria->section  = 'sectionHandle';
  $criteria->postDate = array('and', '> 2014-11-03 23:59:59', '< 2014-11-05 00:00:00');
  $results = $criteria->find();
  
  ```
  
  > **Comments:**
  > **username_0**: This works great username_2. Is there any way I can make it just by the date and not include the time? I tried yii-syntax with **postDate = ['IN', '2014-11-04']** but that got me a "Fatal error: Call to a member function getTimestamp() on a non-object in /craft/app/helpers/DbHelper.php on line 597". Any ideas?  
  > **username_2**: Nothing I can think of...  
  > **username_0**: Is there another way you would recommend me fetching elements from a section posted at a specific date using Craft build in API functions?  
  > **username_2**: Not without directly querying the database.  
  
  ---
  
  