title: Converting "dd/MM/yy hh:mm tt" String To DateTime "yyyy-mm-dd hh:mm:ss.000" And Passing It As SQL Parameter
body: <p>I've always struggled with DateTimes and SQL Server.</p>
  
  <p>Even though I've tested the conversion and I've confirmed that it works.</p>
  
  <pre><code>string date = "21/12/15 11:45 AM";
  DateTime TempDate = DateTime.ParseExact(date, "dd/MM/yy hh:mm tt", CultureInfo.InvariantCulture);
  Console.WriteLine(TempDate);
  //Returns 2015.12.21. 11:45:00
  </code></pre>
  
  <p>When I apply the same logic to SQL it displays the following error: </p>
  
  <blockquote>
    <p>System.ArgumentException: Cannot convert  to System.Int32.<br>
    Parameter name: type ---> System.FormatException: Input string was not in a correct format.</p>
  </blockquote>
  
  <p>When I use the following code</p>
  
  <pre><code>Command.Parameters.Add("@DateNext", SqlDbType.DateTime);
  Command.Parameters["@DateNext"].Value = DateTime.ParseExact(SurDateNext, "dd/MM/yy hh:mm tt", CultureInfo.InvariantCulture);
  //Where SurDateNext is the following string "21/12/15 11:45 AM"
  </code></pre>
  
  <p>The field I'm trying to insert a value is a DateTime with default formatting of <code>yyyy-mm-dd hh:mm:ss.000</code>.</p>
  
  <p>Exactly what am I doing wrong?</p>