dongqu4443 2018-06-21 14:43
浏览 659
已采纳

如何通过使用MySql查询中的日期范围来选择数据?

I have a problem related to MySQL query, I use WAMPServer. I have data in database which have range of dates but when I select data for example

select * from CHD WHERE  addtime>='2018-06-15' and addtime<='2018-06-21';

It displays data from '2018-06-15' to '2018-06-20', data of 2018-06-21 are not displayed even if I do

select * from CHD where addtime='2018-06-21'; 

is not working

Please anyone can help me

  • 写回答

1条回答 默认 最新

  • duanmao1919 2018-06-21 14:47
    关注

    This assumes that your column is of type datetime.

    The shorthand version of your date in the filter clause is assumed to be at midnight of the date. Your values that you are attempting to retrieve have times after midnight of that date. You either need to define a timestamp along with the date, or you need to filter by the day after for less than equal to or the day before for greater than equal

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?