I'm trying to retrieve data from SQL Server using PHP and SQLSRV, but im getting error:
[Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Conversion failed when converting date and/or time from character string. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Conversion failed when converting date and/or time from character string.
Can anyone help me with the issue here. Thanks
<?php
if(isset($_POST['update'])) {
require_once('connection.php');
$recorded_on = $_POST['recorded_on'];
$recorded_end = $_POST['recorded_on'];
//$pin = $_POST['pin'];
$sql = "
SELECT *
FROM dbo.activity_logs
WHERE recorded_on between '.$recorded_on.' and '.$recorded_end.'
";
You can try it too
require_once('connection.php');
$recorded_on = date('Y-m-d',strtotime($_POST['recorded_on']));
$recorded_end = date('Y-m-d',strtotime($_POST['recorded_on']));
//$pin = $_POST['pin'];
$sql = "
SELECT *
FROM dbo.activity_logs
WHERE DATE(recorded_on) between '".$recorded_on."' and '".$recorded_end."'
";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.