title: Time based filtering using sql
body: <p>I need to select data based on date and time.I have two criteria.How to implement this.</p>
  
  <p>1)select the data between 1-1-2013 and 1-10-2013 with time rage between 10  to 16</p>
  
  <p>2)select the data between 1-1-2013 and 1-10-2013 with time range between 20 to 8 next morning</p>
  
  <p>I implemented a code.Its only working for first criteria.Here is that code.</p>
  
  <pre><code> where date&gt;='1-1-2013' AND date &lt;'1-10-2013' 
       AND CAST(date AS TIME) between '10:00' and '16:00'
  </code></pre>
  
  <p>Here the date field in the table is datetime type.Pleases help to solve this</p>