title: Mysql date interval
body: <p>I am trying to select rows which are within a certain time period:</p>
  
  <pre><code>$sql = mysql_query(" SELECT * FROM table WHERE ... AND 
         date BETWEEN ('$date' - Interval 2 YEAR) AND ('$date' + Interval 2 YEAR)
         OR date ISNULL");
  </code></pre>
  
  <p>The format of the dates saved in this column are mm/dd/yyyy</p>
  
  <p>a. how do I select the time interval? currently it is selecting all the rows, not just those within this date range.</p>
  
  <p>b. Am I using the corret syntax to make sure we include all null options as well?</p>
  
  <p><strong>Update.</strong> </p>
  
  <p>Following the answers and comments I changed the column type to "Date" (it was varchar), and have also changed the current type of the existing entries to the correct date format.</p>
  
  <p>I now have 2 questions: 
  a. This is still not working... What else might be the problem?
  b. I want to change in PHP where the entry is saved. How ahould I go about this? Is the following correct:</p>
  
  <pre><code> $new_date = mysql_query("STR_TO_DATE($old_date_string,'%m/%d/%Y')");
  </code></pre>
  
  <p><strong>Solution.</strong></p>
  
  <p>First, I changed the column type to DATE (from VARCHAR).</p>
  
  <p>Second, I moved and converted all the existing entries from their existing column and type (str) to new type (date) and new column.</p>
  
  <p>Third, I added parentheses to the "date" section.</p>
  
  <p>Fourth, I changed <code>ISNULL</code> to <code>IS NULL</code> - addin a space, which changes it from a function to a statement.</p>
  
  <p>Fifth, I am now updating my script so that in the future dates will be saved to the new column in the new type, converting them to the correct fprmat before saving them to the database.</p>
  
  <p>Thankyou @nnicholas and everybody.</p>