我正在使用数据库存储日志,其中“日期”列保存了插入日期。日期的格式为“ MM / DD / YY”。请任何人建议我如何在两个特定日期之间选择数据。例如,我尝试了这个:
$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 }
但是我想这行不通,因为日期不是数字。谢谢您的帮助!:)
使用BETWEEN关键字:
BETWEEN
"SELECT * FROM logs WHERE date BETWEEN '" . $from_date . "' AND '" . $to_date . "' ORDER by id DESC"