title: Comparing dates stored as varchar
body: <p>I need to compare dates that are stored in my database as varchar against today's date.</p>
  
  <p>Specifically,  I need to exclude any records with a date that has passed.</p>
  
  <p>I tried:</p>
  
  <pre><code>SELECT * FROM tblServiceUsersSchedule 
  WHERE ScheduleEndDate !='' AND ScheduleEndDate &lt; '2015/05/31'
  </code></pre>
  
  <p>This selected values such as 17/06/<strong>2012</strong> and 19/04/2015, which have both already passed, along with 01/06/2015 which hasn't.</p>
  
  <p>I then tried to cast the data with:</p>
  
  <pre><code>SELECT * 
  FROM   tblServiceUsersSchedule 
  WHERE  CAST(ScheduleEndDate as DATETIME)  &lt; CAST('05/31/2015' as DATETIME) AND ScheduleEndDate !='' AND ScheduleEndDate is not null
  </code></pre>
  
  <p>But got the following error:</p>
  
  <blockquote>
    <p>The coversion of a varchar data type to a datetime data type resulted
    in an out-of-range value.</p>
  </blockquote>
  
  <p>I checked the data behind and none are null, none are blank white space. All are dates in the format of dd/mm/yyyy.</p>
  
  <p>I can't figure out how to compare the varchar date stored with todays date.</p>