选择两个日期之间的数据?

编程入门 行业动态 更新时间:2024-10-24 04:37:58
本文介绍了选择两个日期之间的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

选择两个日期之间的数据?

本文发布于:2023-10-23 22:43:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1522215.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   两个   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!