<p>Here is syntax you can use to search a date field between two dates.</p>

<pre><code>$startDate = date('Y-m-d', strtotime($settings["start_date"]["date"]));
$endDate = date('Y-m-d', strtotime($settings["end_date"]["date"]));

$criteria-&gt;dateCreated = ['and','&gt;= '.$startDate, '&lt;= '.$endDate];
</code></pre>

CC BY-SA 3.0
2017-09-07T21:12:05.797Z
Sorry, I don't think this works at all for what I'm asking.  You could use this if the entries would have a start_date and an end_date field, but not for what I'm asking.  I want to do this, but against the Date Created field, using a user input for the start and end date, pulling entries that are created between those 2 dates.
Eric Chantigny
CC BY-SA 3.0
2017-09-07T21:21:22.390Z
I have updated the answer.
a-am
CC BY-SA 3.0
2017-09-07T21:28:38.300Z
Yes, it's almost what I ended up with, using your first example.  Thanks for that.  But just so you know, you can't use the DateTime object in this case, trying to concatenate it with a string.  Just use         
$startDate = date('Y-m-d', strtotime($settings["start_date"]["date"]));
$endDate = date('Y-m-d', strtotime($settings["end_date"]["date"]));

If you can update your answer to reflect this, it will be perfect.

Thanks for the help
Eric Chantigny
CC BY-SA 3.0
2017-09-07T21:05:20.857Z
2017-09-07T23:39:00.413Z
2017-09-07T23:39:00.413Z
a-am
<p>I'm building an export plugin in Craft 2 and the entries are saved by the front-end and are never enabled, so no Post Date.  I have a form with the forms.date selectors that sends a start and end date to my controller.  How can I filter on Date Created?  After and before only works on Post Date.</p>

<p>I have this for now:</p>

<pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
$criteria-&gt;section = 'contestEntries';
// Date Created &gt;= start_date
// Date Created &lt;= end_date
$criteria-&gt;status = null;
$entries = $criteria-&gt;find();
</code></pre>

<p>Thank you</p>

<plugin-development><search><elementcriteriamodel>
How to pull entries with Date Created > start and < end?
# How to pull entries with Date Created > start and < end?

(Asked by: username_0 on 2017-09-07)

I'm building an export plugin in Craft 2 and the entries are saved by the front-end and are never enabled, so no Post Date.  I have a form with the forms.date selectors that sends a start and end date to my controller.  How can I filter on Date Created?  After and before only works on Post Date.
I have this for now:
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->section = 'contestEntries';
// Date Created >= start_date
// Date Created <= end_date
$criteria->status = null;
$entries = $criteria->find();

Thank you

**Tags:** plugin-development, search, elementcriteriamodel


---

## 1 answers

### Answer by username_1 on 2017-09-07. Score: 2 | Accepted answer

Here is syntax you can use to search a date field between two dates.
$startDate = date('Y-m-d', strtotime($settings["start_date"]["date"]));
$endDate = date('Y-m-d', strtotime($settings["end_date"]["date"]));

$criteria->dateCreated = ['and','>= '.$startDate, '<= '.$endDate];

> **Comments:**
> **username_0**: Sorry, I don't think this works at all for what I'm asking.  You could use this if the entries would have a start_date and an end_date field, but not for what I'm asking.  I want to do this, but against the Date Created field, using a user input for the start and end date, pulling entries that are created between those 2 dates.  
> **username_1**: I have updated the answer.  
> **username_0**: Yes, it's almost what I ended up with, using your first example.  Thanks for that.  But just so you know, you can't use the DateTime object in this case, trying to concatenate it with a string.  Just use          $startDate = date('Y-m-d', strtotime($settings["start_date"]["date"])); $endDate = date('Y-m-d', strtotime($settings["end_date"]["date"]));  If you can update your answer to reflect this, it will be perfect.  Thanks for the help  

---

