title: how convert string variable to datetime variable in sql-server?
body: <p>I'm relatively new to sql-server; I'm trying to have a start-date and end-date pulled from a form-variable as string then convert it into datetime (yyyy-mm-dd) format and I can't seem to find anything that works. Attempted code and resulting error is below. Any advice would be appreciated.</p>
  
  <pre><code>declare @startdate as varchar
  declare @enddate as varchar
  set @startdate=cast(@startdate as datetime)
  set @enddate=cast(@enddate as datetime)
  
  SELECT order_date, inv_no 
  from invoices 
  where order_date between @startdate and @enddate
  </code></pre>
  
  <p>The error I keep getting is:</p>
  
  <blockquote>
    <p>Conversion failed when converting datetime from character string.</p>
  </blockquote>
  
  <p>How do I fix this?</p>