title: Convert string from PowerShell into sqldbtype. datetime
body: <p>I have two parameters, <code>from</code> and <code>to date</code>. I need to pass from PowerShell to an SQL <a href="http://en.wikipedia.org/wiki/Stored_procedure" rel="nofollow">stored procedure</a>. I created a GUI to input the parameters in the format of 'YYYY-MM-DD'. However, it's a string, and I need to covert it into sqldatetime in the format of 'YYYY-MM-DD, 00:00:000', so that it can result correctly in SQL.</p>
  
  <p>I tried the below, and it's not working. What did I do wrong?</p>
  
  <pre><code>$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
  $SqlConnection.ConnectionString = "Server=localhost;Database=AMSDataWarehouse     test;Integrated Security=SSPI"
  $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
  $SqlCmd.Connection = $SqlConnection
  $SqlCmd.CommandText = "YQBreport1"
  SqlParameter param1 = new SqlParameter("@from",System.Data.SqlDbType.DateTime);
  param1.Value = $from;
  SqlParameter param2 = new SqlParameter("@to",System.Data.SqlDbType.DateTime);
  param2.Value = $to;
  $SqlConnection.Open()
  $sqlcmd.ExecuteNonQuery()
  $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
  $SqlAdapter.SelectCommand = $SqlCmd
  $DataSet = New-Object System.Data.DataSet
  $SqlAdapter.Fill($DataSet)
  $SqlConnection.Close()
  $SQLResult =$DataSet.Tables[0]
  $commands = $SQLResult | foreach-object -process { $_.output }&gt; output.ps1
  .\output.ps1
  </code></pre>