选择两个日期之间的数据? [英] Select data between two dates?

查看:122
本文介绍了选择两个日期之间的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用数据库来存储日志,列日期保存其插入的日期。日期格式为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"

这篇关于选择两个日期之间的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆