无法更正我的代码:从字符串转换日期 and/or 时间时转换失败

Failed to correct my codes: Conversion failed when converting date and/or time from character string

我正在尝试使用 PHP 和 SQLSRV 从 SQL 服务器检索数据,但出现错误:

[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.

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

<?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.'
        ";

你也可以试试

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."'
";