title: How to search between two datetime in php MySQL?
body: <p>I have a table called <strong>reports</strong> in MySQL(MariaDB) . There is a one(out of 5) column named <code>logdate</code> which is is of type <code>datetime</code> .columns stores the the date and time <strong>(in 24hr format)</strong> .
  for ex here is sample value from that column</p>
  <pre><code>2021-04-10 09:35:00
  </code></pre>
  <p>I have to find all reports between a given date <strong>and</strong> time .</p>
  <p>I get 4 variables from form data in PHP</p>
  <pre><code>$fromdate= $_POST['fromdate'];
  $todate= $_POST['todate'];
  $fromtime= $_POST['fromtime'];
  $totime= $_POST['totime'];
  </code></pre>
  <p><code>$fromtime</code> and <code>$totime</code> are just integers with value from 0-23 for hours.
  For example the condition may be like get all data between 4th April 2021
  from 5 o'clock To 8 April 2021  18 o'clock
  <em>i.e.</em>  From <strong>2021-04-04 03:00:00</strong> to <strong>2021-04-08 18:00:00</strong>. There will be never condition on minutes and seconds .</p>
  <p>My question is how to construct a datetime in PHP  compatible with MySQL types so I can have good(efficient, there are millions of records in table ) search speed?
  for ex</p>
  <pre><code>$select = &quot;select * from reports where logdate between ? and ? &quot;; 
  </code></pre>
  <p>P.S: I tried saving date and time as integer as unixtime stamp. But when i convert from and to date received using <code>strttotime()</code> I facing time format issue  due to bug in my code which so can use datetime only.
  If you have any suggestion to improve efficiency of DB please suggest.Thanks</p>