MYSQL检查两个时间戳之间的日期

时间:2018-11-26 19:46:12

标签: php mysql mysqli phpmyadmin

我想检查PHP中两个时间戳之间的数据库内部时间戳中的一个日期,我正在尝试没有任何结果。

$ID = $_SESSION['ID'];
$expiredate = strtotime("-1 month" );
$date      =  time();
$query = "
SELECT * 
  FROM Orders 
 WHERE IDU='$ID' 
   AND Date BETWEEN '.$date.' AND '.$expiredate.'
";
$result = mysqli_query($conn,$query);
$totreward = 0;
while($row = mysqli_fetch_array($result))
{

$paid = $row['Price'];
$totreward += $paid;
}

更新查询,但结果为0

$query = "
SELECT SUM(Price) AS totreward 
  FROM Orders 
 WHERE IDU='$ID'
   AND Date BETWEEN NOW() AND NOW() - INTERVAL 1 MONTH
";
$result = mysqli_query($conn,$query);

$row = mysqli_fetch_assoc($result);
$totreward = $row['totreward'];
$totreward = intval($totreward);

0 个答案:

没有答案