title: How does BETWEEN keyword works into the WHERE statement
body: <p>I'm trying to select all rows from a table that are included into a given time range,</p>
  <p>Suppose I have the following table:</p>
  <pre><code>`range` ( `id`, `from`, `to` )
  </code></pre>
  <p>Where <code>from</code> and <code>to</code> have the type: <code>VARCHAR( 19 )</code> (for YYYY-MM-DD HH:II:SS).</p>
  <p>As these attributes are VARCHAR typed, I'm comparing dates with <code>str_to_date</code>, such as this explainations example: <a href="https://stackoverflow.com/questions/32220641/varchar-date-time-comparison-issue">varchar date time comparison issue</a></p>
  <p>So I first define my time range (with PHP):</p>
  <pre><code>$rangeNow = Date( 'Y-m-d H:i:s' );
  $rangeTo = Date( 'Y-m-d H:i:s', strtotime( '+10 minutes', strtotime( $rangeNow) ) );
  $rangeFrom = Date( 'Y-m-d H:i:s', strtotime( '-10 minutes', strtotime( $rangeTo ) ) );
  </code></pre>
  <p>Here as you can see, it's a range of 20 min:</p>
  <pre><code>echo $rangeFrom.' =&gt; '.$rangeTo;
  
  &gt;&gt; 2022-04-18 17:02:29 =&gt; 2022-04-18 17:22:29
  </code></pre>
  <p>But when I add this condition to my MySQL query (to have all rows starting or ending in this range), I don't get any rows:</p>
  <pre><code>WHERE (
      (
          str_to_date( `range`.`from`, &quot;%Y-%m-%d %h-%i-%s&quot; )
          BETWEEN str_to_date( &quot;'.$rangeFrom.'&quot;, &quot;%Y-%m-%d %h-%i-%s&quot; )
          AND str_to_date( &quot;'.$rangeTo.'&quot;, &quot;%Y-%m-%d %h-%i-%s&quot; )
      )
      OR
      (
          str_to_date( `range`.`to`, &quot;%Y-%m-%d %h-%i-%s&quot; )
          BETWEEN str_to_date( &quot;'.$rangeFrom.'&quot;, &quot;%Y-%m-%d %h-%i-%s&quot; )
          AND str_to_date( &quot;'.$rangeTo.'&quot;, &quot;%Y-%m-%d %h-%i-%s&quot; )
      )
  )
  </code></pre>
  <p>But in my range table, I have the following rows:</p>
  <pre><code>(
      [0] =&gt; Array
          (
              [from] =&gt; 2022-04-18 16:38:41
              [to] =&gt; 2022-04-18 17:12:16
          )
      [1] =&gt; Array
          (
              [from] =&gt; 2022-04-18 16:36:38
              [to] =&gt; 2022-04-18 16:38:28
          )
      [2] =&gt; Array
          (
              [from] =&gt; 2022-04-18 16:33:06
              [to] =&gt; 2022-04-18 16:33:06
          )
  )
  </code></pre>
  <p>It should return the first-one (that is in this range) and no others, do you have any idea about why no rows are selected?</p>
  <p>(without the above WHERE conditions, it select all rows)</p>