Answers.Body: <pre><code>Entry::find()-&gt;startDate('&gt;='. $someTime).endTime('&lt;='.$someOtherTime).all();
  </code></pre>
  
  <p>Those variables can be timestamps, DateTimes or a correctly formated time string.</p>
  
  <p>Here are some variants of these filters</p>
  
  <pre><code>Entry::find()
      -&gt;variantOne('&lt;=' .  Db::prepareDateForDb(new \DateTime())) &lt;-- DateTime object
      -&gt;variantTwo('&lt;=' . time())  &lt;-- as timestamp
      -&gt;variantThree('&lt;=' . (new \DateTime())-&gt;format('U')) &lt;-- timestamp as well
      -&gt;variant(['and', '&lt;=' . time() , '&gt;=' . time() - 3600]) &lt;-- entries within the last hour
      -&gt;validString(['or', '&gt;=' . (new DateTime())-&gt;format('Y-m-d H:i:s'), '&lt;= ' . time()])
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-19T22:26:03.147Z
Answers.Text: I tried `$entites = Entry::find()->startDate('>='. (new \DateTime('now'))->format('m/d/Y') )->all();`, but got an database error like `SQLSTATE[22007]: Invalid datetime format: 7 ERROR: invalid input syntax for type timestamp: ""`
Answers.UserDisplayName: yu xia
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-19T22:49:19.120Z
Answers.Text: @yuxia I've added a few examples
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-19T23:02:45.437Z
Answers.Text: Works just like magic!!! Many many thanks:)
Answers.UserDisplayName: yu xia
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-05-01T14:00:15.323Z
Answers.Text: I had the same problem the other day and solved it like this
  `{% set params = {
    section : 'theSection',
    startDate : '>=' ~ someTime,
    endDate : '<=' ~ someOtherTime,
  } %}
  {% set entries = craft.entries(params).all() %}`
  Are there benefits to `Entry::find()` over `craft.entries(params)`?
Answers.UserDisplayName: Johann Dyck
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-05-01T14:02:04.883Z
Answers.Text: @JohannDyck `Entry::find` is PHP Syntax, `craft.entries` is twig syntax that executes `Entry::find()` You can see what `craft.entries` does here https://github.com/craftcms/cms/blob/develop/src/web/twig/variables/CraftVariable.php#L262
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-19T21:47:08.063Z
Answers.LastActivityDate: 2018-04-19T22:55:09.110Z
Answers.LastEditDate: 2018-04-19T22:55:09.110Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I'm using Craft 3 and I would like to do the following thing:</p>
  
  <p>There is a start date and an end date filed in entry, is it possible to get entries that are between these two dates in PHP?</p>
  
  <p>Thank you! </p>
  
Tags: <datetime>
Title: How to get entries between a time
ThreadText: # How to get entries between a time
  
  (Asked by: username_0 on 2018-04-19)
  
  I'm using Craft 3 and I would like to do the following thing:
  
  There is a start date and an end date filed in entry, is it possible to get entries that are between these two dates in PHP?
  
  Thank you!
  
  **Tags:** datetime
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-04-19. Score: 4 | Accepted answer
  
  ```
  Entry::find()->startDate('>='. $someTime).endTime('<='.$someOtherTime).all();
  
  ```
  
  Those variables can be timestamps, DateTimes or a correctly formated time string.
  
  Here are some variants of these filters
  
  ```
  Entry::find()
      ->variantOne('<=' .  Db::prepareDateForDb(new \DateTime())) <-- DateTime object
      ->variantTwo('<=' . time())  <-- as timestamp
      ->variantThree('<=' . (new \DateTime())->format('U')) <-- timestamp as well
      ->variant(['and', '<=' . time() , '>=' . time() - 3600]) <-- entries within the last hour
      ->validString(['or', '>=' . (new DateTime())->format('Y-m-d H:i:s'), '<= ' . time()])
  
  ```
  
  > **Comments:**
  > **username_0**: I tried `$entites = Entry::find()->startDate('>='. (new \DateTime('now'))->format('m/d/Y') )->all();`, but got an database error like `SQLSTATE[22007]: Invalid datetime format: 7 ERROR: invalid input syntax for type timestamp: ""`  
  > **username_1**: @username_0 I've added a few examples  
  > **username_0**: Works just like magic!!! Many many thanks:)  
  > **username_2**: I had the same problem the other day and solved it like this `{% set params = {   section : 'theSection',   startDate : '>=' ~ someTime,   endDate : '<=' ~ someOtherTime, } %} {% set entries = craft.entries(params).all() %}` Are there benefits to `Entry::find()` over `craft.entries(params)`?  
  > **username_1**: @username_2 `Entry::find` is PHP Syntax, `craft.entries` is twig syntax that executes `Entry::find()` You can see what `craft.entries` does here https://github.com/craftcms/cms/blob/develop/src/web/twig/variables/CraftVariable.php#L262  
  
  ---
  
  