It's kind of offtopic, but i come here from googling the same error. For me this error appeared when i was selecting datetime field from mssql database and than using it later in php-script. like this:
$SQL="SELECT Created
FROM test_table";
$stmt = sqlsrv_query($con, $SQL);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true));
}
$Row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC);
$SQL="INSERT INTO another_test_table (datetime_field) VALUES ('".$Row['Created']."')";
$stmt = sqlsrv_query($con, $SQL);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true));
}
the INSERT statement was giving error: Object of class DateTime could not be converted to string
I realized that you CAN'T just select the datetime from database:
SELECT Created FROM test_table
BUT you have to use CONVERT for this field:
SELECT CONVERT(varchar(24),Created) as Created FROM test_table