I’ve not been able to find a working answer to this question anywhere-which is really weird if you ask me. Every attempt to pass the datetime to the database has failed with a conversion type string error. The SQL Server i’m using has a column on a table that is of type “datetime” and an example value is
My current script is:
$dateString = "2009-09-16 00:00:00.000" $id = '12345' $nd = Get-Date $dateString -Format "yyyy-MM-dd HH:mm:ss:fff" $query = "Update MyTable Set CreateDate = '@e1' Where ID = '@e2'" $SqlCmd.Parameters.Clear() $parm = $SqlCmd.Parameters.Add("@e1", $nd) $SqlCmd.Parameters.Add("@e2" , $id) $SqlCmd.CommandText = $query $SqlCmd.ExecuteNonQuery()I have tried adding [datetime] to the $nd-but again getting the same kind of failure. The database or powershell just doesn't like the execution.