简体   繁体   English

使用 PHP 变量和 STR_TO_DATE 的 MySQL 日期范围

[英]MySQL date range using PHP variables and STR_TO_DATE

After passing in values to from and to via this call:通过此调用将值传入fromto

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM