本文介绍了选择两个日期之间的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用数据库来存储日志,列日期保存其插入的日期。日期格式为MM / DD / YY。请任何人建议如何在两个特定日期之间选择SELECT数据。例如,我尝试过:
I'm using a database to store logs, with a column "date" which holds the date it was inserted. The format of the date is "MM/DD/YY". Please can anyone suggest how I would SELECT data in between two certain dates. For example, I tried this:
$from_date = "01/01/12"; $to_date = "02/11/12"; $result = mysql_query("SELECT * FROM logs WHERE date >= " . $from_date . " AND date <= " . $to_date . " ORDER by id DESC"); while($row = mysql_fetch_array($result)) { // display results here }但是我猜这不行,因为日期不是数字。谢谢您的帮助! :
But I guess this doesn't work because the dates aren't numbers. Thanks for the help! :)
推荐答案使用 BETWEEN 关键字:
"SELECT * FROM logs WHERE date BETWEEN '" . $from_date . "' AND '" . $to_date . "' ORDER by id DESC"更多推荐
选择两个日期之间的数据?
发布评论