[英]MySQL date range using PHP variables and STR_TO_DATE
After passing in values to from
and to
via this call:通过此调用将值传入
from
和to
:
getTransactions.php?from=05/01/17&to=05/31/17
I get nothing returned from the MySQL call:我从 MySQL 调用中没有得到任何返回:
$data = $pdoProducts->query("SELECT * FROM `transactions`
WHERE STR_TO_DATE(date, '%m/%d/%y')
BETWEEN STR_TO_DATE($from, '%m/%d/%y')
AND STR_TO_DATE($to, '%m/%d/%y')")->fetchAll(PDO::FETCH_ASSOC);
I have several other calls that do work using the STR_TO_DATE
method and the date in the table, so I know that the data in the table is correctly formatted.我还有其他几个使用
STR_TO_DATE
方法和表中的日期工作的调用,所以我知道表中的数据格式正确。
However, I still cannot get this date range to work.但是,我仍然无法使此日期范围起作用。 Am I formatting something wrong?
我的格式有问题吗?
If Data type is varchar
如果数据类型是
varchar
SELECT * FROM user_attendance
WHERE STR_TO_DATE(date, '%d/%m/%Y')
BETWEEN STR_TO_DATE('21/05/2014', '%d/%m/%Y')
AND STR_TO_DATE('21/06/2014', '%d/%m/%Y')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.