Yousef Altaf Yousef Altaf - 5 months ago 8
MySQL Question

Select from my tabel where date = specific date

My date in table is

TIMESTAMP
something like this
2016-05-28 18:39:00


Now I am trying to select from table where date =
2016-05-28


here is my query

$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()) {


Date is coming from here

$dateOfBirth = $_POST['dateOfBirth'];


results are empty

Answer

could be you need a correct date format

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') = ?
Comments