修正我的代码失败。从字符串转换日期或时间时,转换失败。

问题描述 投票:0回答:1

我试图使用PHP和SQLSRV从SQL Server中检索数据,但得到了错误。

[Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Conversion failed when converting date andor time from character string. [信息] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Conversion failed when converting date andor time from character string.

谁能帮我解决这里的问题。谢谢你的帮助

<?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.'
        ";
php sql-server sqlsrv
1个回答
0
投票

你也可以试试

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."'
";
© www.soinside.com 2019 - 2024. All rights reserved.