title: Comparing dates in SQL returns wrong records
body: <p>I am trying to locate a date in database between two specific dates entered by user. Something like:</p>
  
  <p>SELECT date FROM table WHERE date>=dateFrom AND date&lt;=dateTO</p>
  
  <p>I have the following table:</p>
  
  <p><img src="https://i.stack.imgur.com/p5mZx.png" alt="enter image description here"></p>
  
  <p>I have made a mistake saving the date as VARCHAR and now i have to do all the str_to_date and date_format as i am using phpMyAdmin. I somehow did it but i am facing this strange problem using this query:</p>
  
  <pre><code>SELECT date_format(str_to_date(data,'%d/%m/%Y'),'%d/%m/%Y') AS data FROM montaggio WHERE data&gt;=date_format(str_to_date('29/08/2014','%d/%m/%Y'),'%d/%m/%Y')
  </code></pre>
  
  <p>The query would return to me only the date <code>19/08/2014</code> where as i expected it to return <code>01/09/2014</code>. On the other hand if it enter the query </p>
  
  <pre><code>SELECT date_format(str_to_date(data,'%d/%m/%Y'),'%d/%m/%Y') AS data FROM montaggio WHERE data&gt;=date_format(str_to_date('29/08/2014','%d/%m/%Y'),'%d/%m/%Y') AND data&lt;=date_format(str_to_date('05/09/2014','%d/%m/%Y'),'%d/%m/%Y')
  </code></pre>
  
  <p>The query returns nothing.</p>
  
  <p>I am using phpMyAdmin.
  What am i missing here? Any help would be appreciated!</p>