I am trying to insert a datetime into an MSSQL database, but I do not get it, I always get an error. I have read all over the internet and there is no one who has had a problem like this, what can it be?
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require "init.php";
$name = "20498090R";
$entSal = "1";
$ts = "2017-04-19 13:36:43";
$motivos = "";
$actividades = "";
$laobra = "PRY12345";
$newdate = date('Y-m-d H:i:s', strtotime($ts));
$pruebas = sqlsrv_num_rows($probar);
$comprobar = "SELECT * FROM [dbo].[Empleados] WHERE NIF ='".$name."';";
$probar = sqlsrv_query($con, $comprobar);
if(sqlsrv_has_rows($probar) === false){
echo 'Usuario no registrado en el sistema';
}else{
$sql = "INSERT INTO [dbo].[Fichajes] ( Empleado, Obra, Hora, Entrada,
Motivo, Actividad) VALUES ('".$name."','".$laobra."','".$newdate."','".$entSal."','".$motivos."','".$actividades."');";
if(!sqlsrv_query($con, $sql)){
die( print_r( sqlsrv_errors(), true));
}
}
?>
ERROR MSJ:
Array ( [0] => Array ( [0] => 22007 [SQLSTATE] => 22007 [1] => 242 [code] => 242 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Converting the varchar data type to datetime produced a value out of range. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]La conversi�n del tipo de datos varchar en datetime produjo un valor fuera de intervalo. ) [1] => Array ( [0] => 01000 [SQLSTATE] => 01000 [1] => 3621 [code] => 3621 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Se termin� la instrucci�n. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Se termin� la instrucci�n. ) )
If I do not do the $newdate variable the same problem I have