title: Sybase - Selecting data between 2 dates
body: <p>I have another (probably) very easy question to answer regarding sybase ASE 15.5...not my hot topic :-(</p>
  
  <p>I have a temp table which has a date column.</p>
  
  <p>The date is inserted into the temp table using conversion which converts the LIVE data </p>
  
  <p>From </p>
  
  <p>e.g.:</p>
  
  <pre><code>2013-01-21 10:05:00.0
  2013-01-28 08:03:00.0
  </code></pre>
  
  <p>to</p>
  
  <pre><code>21/01/2013
  28/01/2013
  
  using (CONVERT(VARCHAR(10), DATEFIELD, 103)
  </code></pre>
  
  <p>The problem I am facing is when I try to select data from the LIVE table into the temp table using a date range filter:</p>
  
  <pre><code>WHERE (CONVERT(VARCHAR(10), DATEFIELD, 103) BETWEEN '21/01/13' AND '28/01/13') 
  </code></pre>
  
  <p>....when I run this sybase only inserts the 21/01/2013 date and not the 28/01/2013.</p>
  
  <p>.....furthermore if I use 29/01/2013 as end date instead i.e.</p>
  
  <pre><code>WHERE (CONVERT(VARCHAR(10), DATEFIELD, 103) BETWEEN '21/01/13' AND '29/01/13') 
  </code></pre>
  
  <p>I get both inserted:</p>
  
  <pre><code>21/01/2013
  28/01/2013
  </code></pre>
  
  <p>further furthermore - if I run only 21/01/13 i.e.</p>
  
  <pre><code>WHERE (CONVERT(VARCHAR(10), DATEFIELD, 103) BETWEEN '21/01/13' AND '21/01/13') 
  </code></pre>
  
  <p>I get nothing returned.</p>
  
  <p>Any ideas?</p>
  
  <p>Perhaps using BETWEEN in sybase is no good.  Just to be clear the fields are converted from DATETIME to VARCHAR (10).</p>
  
  <p>Another problem I have is when I have this first part fix I want to be able to pass a wildcard in e.g.</p>
  
  <pre><code>WHERE (CONVERT(VARCHAR(10), DATEFIELD, 103) BETWEEN '%' AND '%') 
  </code></pre>
  
  <p>....but at the moment this one doesn't work either.</p>
  
  <p>Any idea's on either/both of these issues.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Gareth</p>