我试图仅显示今天的结果信息。
我正在使用的以下示例在24小时内显示信息。
我只需要显示当前日期信息。
范例:
$sql = "SELECT COUNT(*) as c
FROM toutcome
WHERE AffID = '$affID' AND
CompletedDate > DATE_SUB(CURDATE(), INTERVAL 1 DAY) ";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
echo $row['c'] ;
我也尝试过
$sql = "SELECT COUNT(*) as c
FROM toutcome
WHERE AffID = '$affID' AND
CompletedDate > DATE_SUB(CURDATE(), INTERVAL 24 HOUR) ";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
echo $row['c'] ;
最佳答案
尝试:
SELECT COUNT(*) as c FROM toutcome WHERE AffID = '$affID' AND CompletedDate BETWEEN CURDATE() AND NOW()
如果您知道
CompletedDate
永远不会出现,那么:SELECT COUNT(*) as c FROM toutcome WHERE AffID = '$affID' AND CompletedDate >= CURDATE()
阿伦的解决方案不会在
CompletedDate
上使用索引。