title: How to query a date interval in a database in java?
body: <p>I have a table and a date column where i keep timestamp value with the following format:</p>
  
  <pre><code>yyyy-MM-dd HH:mm:ss
  </code></pre>
  
  <p>Then i want to make a query that returns me specific time intervals. I give a start date and an end date. HEre is what i did:</p>
  
  <pre><code>PreparedStatement find = (PreparedStatement) con.prepareStatement("select * from transactions where transid=? and date &gt;= ? and date &lt;= ?");
  
      find.setString(1, selected.getIban());
      find.setDate(2, (Date) dt1);
      find.setDate(3, (Date) dt2);
  
      ResultSet res=find.executeQuery();
  
      while(res.next()){
          ....
      }
  </code></pre>
  
  <p>While debugging i see that dt1 and dt2 are set correctly with the following format:</p>
  
  <pre><code>yyyy-MM-dd
  </code></pre>
  
  <p>This resultset has no results in it (not null, but empty) and while loop does not execute. Can't i use >= and &lt;= to do this as i did in my query? Or is it because i store timestamp in db but query with date, and these to have different formats.</p>
  
  <p>Thank you</p>