MySQLi DATE_FORMAT根本不工作 [英] MySQLi DATE_FORMAT not working at all
本文介绍了MySQLi DATE_FORMAT根本不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码,数据库列已经获得了日期和时间,我只想使用数据部分搜索记录。我有以下,但我有一种感觉是非常错误的。
I have the following code, the database column has got the date and time, I want to search for records using just the data part. I have the following but I have a feeling it is very wrong.
$query = "SELECT id,uid,product,jpgID,saledatetime FROM sales WHERE printed = ? AND DATE_FORMAT('?', 'y/m/d') AS saledatetime";
编辑:
现在工作,谢谢:
Working now, thanks:
if(login_check($mysqli) == true) {
//logged in
$session_date = $_SESSION['session_date'];
$query = "SELECT id,uid,product,jpgID,saledatetime
FROM sales
WHERE printed = ?
AND DATE_FORMAT(saledatetime , '%y/%m/%d') = ?";
if ($stmt = $mysqli->prepare($query)) {
$printed = 0;
$stmt->bind_param("is",$printed,$session_date);
$stmt->execute();
$stmt->store_result();
//Get result
$stmt->bind_result($result_id,$result_uid,$result_product,$result_jpgID,$result_saledatetime);
//Number of rows returned
$count_rows = $stmt->num_rows;
echo $count_rows;
}
} else {
header("Location: index.php");
}
推荐答案
DATE_FORMAT有特殊语法。查询没有将格式化的datetime与任何东西进行比较,所以我认为它是这样的?
DATE_FORMAT has special syntax. Query didn't compare formatted datetime to anything, so I presume it was meant to be like this?
SELECT id, uid, product, jpgID, saledatetime
FROM sales
WHERE printed = ?
AND DATE_FORMAT(saledatetime, '%y/%m/%d') = DATE_FORMAT(?, '%y/%m/%d')
这篇关于MySQLi DATE_FORMAT根本不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文