$query = "SELECT * FROM justshawarma_nexo_commandes where REF_CLIENT = '$uuc'
and DATE_CREATION like '%$date3%' and DATE_CREATION like '%$date4%'";
这是我的查询。我想获取两个日期之间匹配的记录。但是我在表格中的日期列包含日期和时间。这就是为什么我想要使用和之间。
此代码中的错误是什么?
答案 0 :(得分:0)
使用BETWEEN条件:
$query = "SELECT * FROM justshawarma_nexo_commandes where REF_CLIENT = '$uuc' and DATE_CREATION BETWEEN '$date3' and '$date4'";
答案 1 :(得分:0)
像您的查询将看起来像下面的东西
$query = "SELECT * FROM justshawarma_nexo_commandes
where REF_CLIENT = \'$uuc\'
and DATE_CREATION like %\'$date3\'%
and DATE_CREATION like %\'$date4\'%";
与之间
$query = "SELECT * FROM justshawarma_nexo_commandes
where REF_CLIENT = \'$uuc\'
and DATE_CREATION Between \'$date3 00:00:00\'
and \'$date4 23:59:59\'";
正如您所说,您的专栏中有时间,因此您可以使用这些查询选择该日期范围之间的所有记录。
答案 2 :(得分:0)
$between['date_from'] = date("Y-m-d", strtotime($date3))." 00:00:00";
$between['date_to'] = date("Y-m-d",strtotime($date4))." 23:59:59";
$query = "SELECT * FROM justshawarma_nexo_commandes where REF_CLIENT = '$uuc' and DATE_CREATION BETWEEN '".$between['date_from']."' AND '".$between['date_to']."';
答案 3 :(得分:0)
尝试一下。这对我来说很好,在这里,我的Order_ID的一部分具有日期:
gtk-font-name = "DejaVu Sans 11"
答案 4 :(得分:0)
在您的 SQL 语句中包含 DATE()
,因为您说您的列包含日期时间,例如……
$query = "SELECT * FROM justshawarma_nexo_commandes where REF_CLIENT = '$uuc'
and DATE(DATE_CREATION) BETWEEN '$date3' and '$date4'";