<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>

CC BY-SA 3.0
2015-03-19T17:51:31.927Z
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?
naboovalley
CC BY-SA 3.0
2015-03-19T17:56:04.753Z
Nothing I can think of...
Brad Bell
CC BY-SA 3.0
2015-03-19T18:00:50.087Z
Is there another way you would recommend me fetching elements from a section posted at a specific date using Craft build in API functions?
naboovalley
CC BY-SA 3.0
2015-03-19T22:26:12.663Z
Not without directly querying the database.
Brad Bell
CC BY-SA 3.0
2015-03-19T17:13:54.013Z
2015-03-19T17:13:54.013Z
Brad Bell
<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>

CC BY-SA 4.0
2023-10-26T00:06:59.620Z
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'.
Jason McKinney
<plugin-development><elementcriteriamodel>
How do I get elements using getCriteria from a specific date?
# 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 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?  
> **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.  

---

