title: Mysql between two datetime columns
body: <p>I have the following code and it doesn't seem to be generating the expected results:</p>
  
  <pre><code>$date_from = '2012-04-27 18:19:33';
  $date_to = '2012-05-29 00:59:57';
  
  $database-&gt;connect(); 
          $ancestors = mysql_query('
              SELECT * FROM ' . $database-&gt;db_prefix . 'comments e
                  WHERE e.created BETWEEN "' . $date_from . '" AND "' . $date_to . '" AND   
                      e.ancestors = "' . $comment["id"] . '" AND e.user_id != "' . $user-&gt;user_object["id"] . '" AND
                          NOT EXISTS
                          (
                              SELECT null 
                              FROM ' . $database-&gt;db_prefix . 'notifications d
                              WHERE  d.target_id = e.id
                          )
                          ORDER BY e.created DESC
          ', $database-&gt;connection_handle);
      $database-&gt;close();
  </code></pre>
  
  <p>It may be a silly error.. But I'm finding it hard to be sure when i'm unsure if the select statement BETWEEN and the dates being used are valid MYSQL things.</p>
  
  <p>Any help would be great. I have been scouring and what I am doing seems to be correct thus the confusion.</p>
  
  <p>EDITED // </p>
  
  <p>I have many comments made between the date_from and date_to dates and there are no notifications in the notifications table (not exists  part)... So basically, I should get about 25 comments back... Instead I just get one comment returned which has a date of 2012-05-29 00:23:39  </p>
  
  <p>EDITED //</p>
  
  <p>Is it because you can only compare a date to a date.. and a time to a time? How might I adapt the mysql in order to do this?</p>
  
  <p>EDITED //</p>
  
  <p>It's definetley the between function going wrong. I'm really unsure of what the hell is going wrong with it.</p>
  
  <ol>
  <li>Can you return records between 2 dates?</li>
  <li>Can you give an example?</li>
  </ol>
  
  <p>EDITED //
  Problem has been solved. It was nothing to do with the query so its safe to say this is the correct way of doing it. I had done my date ranges in a bonkers way. Thanks for all ur freaking help guys!!!!</p>