1

我有我的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

我想在 end_date 之前显示消息,start_date is equal to today and today is greater than start_date并且以同样的方式显示消息 ``before 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。那么有人可以告诉我该怎么做吗?任何帮助和建议都将是非常可观的。谢谢

4

1 回答 1

1

我认为这是你需要的:

编辑:

SELECT * FROM messages WHERE NOW() BETWEEN start_date AND 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();
于 2013-09-28T20:09:39.690 回答