I want to make a query to base de datos
in sql server
where the field is of type datetime. At the moment of doing this in PHP
it shows me the following error:
Warning: strtotime () expects parameter 1 to be string, object given in C: \ xampp \ htdocs \ sana_php \ kardex.php on line 44
Warning: strtotime () expects parameter 1 to be string, object given in C: \ xampp \ htdocs \ sana_php \ kardex.php on line 44
<?php session_start();
if (isset($_SESSION['usuario'])) {
require 'vistas/kardex.view.php';
}else{
header('location: servicios.php');
}
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$buscar=filter_var($_POST['buscar'], FILTER_SANITIZE_STRING);
$fecha1=date('d-m-Y', strtotime($_POST['fecha1']));
print_r($fecha1);
$fecha2=date('d-m-Y', strtotime($_POST['fecha2']));
$serverName="(LOCAL)";
$connectionInfo=array("Database"=>"dbsav300", "UID"=>"sa", "PWD"=>"admin01");
$conn=sqlsrv_connect($serverName, $connectionInfo);
if ($conn) {
# code...
}else{
echo "Conexion no pudo establecerse";
die(print_r(sqlsrv_errors(), true));
}
$query="SELECT art_Clave, art_Costo, kar_Fecha, kar_Cantidad, kar_Origen, alma_Existencia FROM tArticuloKardex WHERE art_Clave='".$buscar."' AND (kar_Fecha BETWEEN '".$fecha1."' AND '".$fecha2."')";
print_r($query);
$resultado=sqlsrv_query($conn, $query);
//se desplegaran los resultados en la tabla
echo "<table border=1>";
echo "<tr>";
echo "<th>SKU</th>";
echo "<th>COSTO</th>";
echo "<th>FECHA DE MOVIMIENTO</th>";
echo "<th>PIEZAS</th>";
echo "<th>TICKET</th>";
echo "<th>EXISTENCIA FINAL</th>";
echo "</tr>";
while($row=sqlsrv_fetch_array($resultado)){
echo '<tr>';
echo '<td>'.$row['art_Clave'].'</td>';
echo '<td>'.$row['art_Costo'].'</td>';
echo '<td>'.date('d-m-Y', strtotime($row['kar_Fecha'])).'</td>';
echo '<td>'.$row['kar_Cantidad'].'</td>';
echo '<td>'.$row['kar_Origen'].'</td>';
echo '<td>'.$row['alma_Existencia'].'</td>';
echo '</tr>';
}
echo "</table>";
}
?>