Mysql 仅显示日期之间的消息


Mysql show only the messages in between dates

我的mysql数据库表消息是这样的

id   message    start_date    end_date
1    message1   2013-09-29    2013-11-30
2    message2   2013-08-20    2013-09-30
3    message3   2013-06-20    2014-01-01
4    message4   2013-06-06    2013-09-20
5    message5   2013-10-25    2014-03-05

我想在start_date is equal to today and today is greater than start_date时显示消息,并且以同样的方式显示消息"在end_date之前。一旦end_date被越过,那么它不应该显示消息。为此,我这样做了

SELECT * FROM messages WHERE start_date >= CURDATE( )  and end_date >= CURDATE( );

但是这个显示了所有开始日期尚未到来的消息。就像5th(5 message5 2013-10-25 2014-03-05)行一样.所以我只想要start_date之间的消息是今天,start_date已经被交叉,它会显示到end_date。那么有人可以告诉我如何做到这一点吗?任何帮助和建议都将非常可观。谢谢

我认为这就是你需要的:

编辑:

从 start_date 和 end_date 之间的消息中选择 *;
SELECT * FROM messages WHERE CURDATE() BETWEEN start_date AND end_date;

仅供参考,在您的原始查询中,您只需在比较运算符时更改运算符的方向start_date:

SELECT * FROM messages WHERE start_date <= CURDATE() and end_date >= CURDATE();