title: MSSQL Server 2008 Conversion failed when converting date and/or time from character string Error
body: <p>I am currently receiving the MSSQL Server 2008 error: <code>Conversion failed when converting date and/or time from character string.</code></p>
  
  <p>I've checked the following threads but am still having no lucks:</p>
  
  <p><a href="https://stackoverflow.com/questions/14119133/conversion-failed-when-converting-date-and-or-time-from-character-string-while-i">Conversion failed when converting date and/or time from character string while inserting datetime</a>
  <a href="https://stackoverflow.com/questions/24907360/conversion-failed-when-converting-date-and-or-time-from-character-string-in-sql">Conversion failed when converting date and/or time from character string in SQL SERVER 2008</a></p>
  
  <p>Here is the query (I'm using PHP's PDO SQLSRV):</p>
  
  <pre><code>SELECT ISNULL(MYDATE,'None') AS MYDATE, 
  ISNULL(CAST(rnm AS NVARCHAR(50)),'None') AS Rnm, 
  DATENAME(dw, MYDATE) as nameOfDay, 
  FROM tab1
  INNER JOIN rnm ON (tab1.rte = rnm.rte)
  WHERE DATEDIFF(S, '1970-01-01', MYDATE) &gt;= :startDate
  AND DATEDIFF(S, '1970-01-01', MYDATE) &lt;= :endDate
  GROUP BY MYDATE, CAST(rnm AS NVARCHAR(50)) WITH ROLLUP
  </code></pre>
  
  <p>The MYDATE field is of the type <code>datetime</code> in MSSQL.  I have tried casting each of the MYDATE variables and the <code>1970-01-01</code> all as datetime, but I still receive the error.  </p>
  
  <p>The "rnm" is cast as VARCHAR because it's an old DB using the "text" type still, unfortunately.</p>
  
  <p>Thanks.</p>
  
  <p>---update:</p>
  
  <pre><code>$startDate = strtotime($_GET['startDate'] . " 00:00:00");
  $endDate = strtotime($_GET['endDate'] . " 23:59:59");
  </code></pre>
  
  <p>The above is then bound to the prepared variable via <code>bindParam()</code>.</p>