title: SQL Server : error converting data type nvarchar to datetime
body: <p><strong>EDIT</strong>
  <em>Thank you for all your help.</em></p>
  
  <p>First thing, I have read tons of post and question of people having this same error, mines varies for <code>int</code> and <code>bigint</code> but the error stays the same, I can not insert or update. I am working with Microsoft SQL Server 2017 Management Studio  and I've having this problem for the last two to three days, I know there are tons of answers I just don't know the F is wrong.</p>
  
  <p>This is my stored procedure: </p>
  
  <pre><code>SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  
  ALTER PROCEDURE [dbo].[myproc]
      (@name VARCHAR(50),
       @ID BIGINT,
       @birthdate DATETIME,
       @Enabled BIT,
       @married BIT,
       @employees INT,
       @hiredDate DATETIME)
  AS
  BEGIN 
      SET NOCOUNT ON
  
      DECLARE @sql AS NVARCHAR(MAX)       
      SET @sql ='IF EXISTS(SELECT * FROM MyTable WHERE MyTable.ID ='+@ID+')
                       UPDATE MyTable
                       SET
                       name ='+@name+'
                      ,birthdate='+@birthdate+'
                      ,Enabled ='+@Enabled+'
                      ,married='+@married+'
                      ,employees='+@employees+'
                      ,hiredDate='+@hiredDate+'
                      where ID = '+@ID+'
                  ELSE
                  INSERT INTO MyTable(name,ID,birthdate,Enabled,married,employees,hiredDate)VALUES(
                  '+@name+','+@ID+','+convert(varchar,@birthdate,20)+','+@Enabled+','+@married+','+@employees+','+convert(varchar,@hiredDate,20)+')'
  
      EXEC (@SQL)
  END
  </code></pre>
  
  <p>I am sick of this damn error and I am losing it.</p>
  
  <blockquote>
    <p>Msg 8114, Level 16, State 5, Procedure testinsert, Line 0 [Batch Start Line 0]<br>
    Error converting data type varchar to datetime.</p>
  </blockquote>
  
  <p>I made this little table just so i could ask and try to make this trial</p>
  
  <p>I run this stored procedure with:</p>
  
  <pre><code>DECLARE @return_value INT
  
  EXEC @return_value = testinsert
          @name = 'asd',
          @ID = 25,
          @birthdate = '2018-12-10 16 45 00',
          @Enabled = 1,
          @married = NULL,
          @employees = NULL,
          @hiredDate = NULL
  
  SELECT  'Return Value' = @return_value
  GO
  </code></pre>
  
  <p>Table:</p>
  
  <pre><code>[dbo].[MYDTABLE]
             ([name]
             ,[ID]
             ,[birthdate]
             ,[Enabled]
             ,[married]
             ,[employees]
             ,[hiredDate])
       VALUES
             (&lt;name, varchar(50),&gt;
             ,&lt;ID, bigint,&gt;
             ,&lt;birthdate, datetime,&gt;
             ,&lt;Enabled, bit,&gt;
             ,&lt;married, bit,&gt;
             ,&lt;employees, int,&gt;
             ,&lt;hiredDate, datetime,&gt;)
  GO
  </code></pre>