title: convert string to datetime in function SQL Server
body: <p>I have been writing a user-defined function in SQL Server:</p>
  
  <p>It looks like this :</p>
  
  <pre><code>CREATE FUNCTION FormatDate(@fromtime nvarchar(50))
  RETURNS DATETIME
  AS 
  BEGIN
  
      DECLARE @tempfrom datetime
      DECLARE @tempto nvarchar(50)
  
      set @tempfrom =  Convert(datetime, @fromtime, 100) 
      RETURN @tempfrom
  
  END
  
  select dbo.FormatDate('08/17/2010 4:30')
  </code></pre>
  
  <p>When I try to run this, I get the following error:</p>
  
  <blockquote>
    <p>Conversion failed when converting the nvarchar value '08/17/2010 4:30' to data type int.</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>