本文介绍了日期之间的SQL,包括开始日期和结束日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有这个:
(CURDATE() BETWEEN start_date AND end_date)
工作正常.
但是当CURDATE()
是2011-12-02且end_date
是2011-12-02时,它会抢行吗?
But when the CURDATE()
is 2011-12-02 and the end_date
is 2011-12-02 will it grab the row?
例如,我的开始日期是2011-12-01 00:00:00,结束日期是2011-12-02 23:59:59
E.g my start_date is 2011-12-01 00:00:00 and my end date is 2011-12-02 23:59:59
因此,仅当日期介于两者之间时,它才起作用;如果日期在end_date
本身上,则它不起作用.
So it only works when the date is between but not if it's ON the end_date
itself.
或者也许它也应该检查时间,因为例如在2011-12-02 15:30:00时仍需要使用此查询选择它.
Or maybe it should check for the time too, because it still needs to be selected with this query when it's 2011-12-02 15:30:00 for example.
我该怎么做?
推荐答案
好吧,你可以尝试
CURDATE() BETWEEN start_date AND DATE_ADD(end_date, INTERVAL 1 DAY)
这篇关于日期之间的SQL,包括开始日期和结束日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!