从我的表格中选择日期=特定日期

时间:2016-06-20 20:22:05

标签: mysql date

我在表中的日期为TIMESTAMP,类似2016-05-28 18:39:00

现在我正在尝试从日期= 2016-05-28

的表格中进行选择

这是我的查询

    $getReport = $db->prepare('SELECT a.proId, a.userId, DATE(a.date), a.status, a.canceledBy, b.id, b.pName, b.pPrice FROM purchaseshistory AS a INNER JOIN products AS b ON(a.proId=b.id) WHERE a.date=?');

    $getReport->bind_param('i', $dateOfBirth);
    $getReport->execute();
    $getReport->bind_result($proId, $userId, $date, $status, $canceledBy, $id, $pName, $pPrice);
$getReport->store_result();
while ($getReport->fetch()) {

日期来自这里

$dateOfBirth = $_POST['dateOfBirth'];

结果为空

2 个答案:

答案 0 :(得分:0)

您已在SELECT中将a.date转换为DATE,但在WHERE子句中没有,我建议您修改查询,如下所示:

SELECT 
  ph.proId, ph.userId, DATE(ph.date), ph.status, ph.canceledBy,
  p.id, p.pName, p.pPrice 
FROM purchaseshistory AS ph 
  INNER JOIN products AS p ON ph.proId = p.id
WHERE DATE(ph.date) = ?

答案 1 :(得分:0)

可能需要正确的日期格式

SELECT a.proId, a.userId, 
DATE(a.date), a.status, a.canceledBy, b.id, b.pName, b.pPrice 
FROM purchaseshistory AS a 
INNER JOIN products AS b ON(a.proId=b.id) 
WHERE date_format(a.date,'%Y-%m-%d') = ?