简体   繁体   English

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

[英]How to select data by using range of dates in MySql query?

I have a problem related to MySQL query, I use WAMPServer. 我有一个与MySQL查询相关的问题,我使用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 它显示从'2018-06-15'到'2018-06-20'的数据,即使我这样做也不会显示2018-06-21的数据

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

is not working 不管用

Please anyone can help me 请任何人都可以帮助我

This assumes that your column is of type datetime. 假设您的列的类型为datetime。

The shorthand version of your date in the filter clause is assumed to be at midnight of the date. filter子句中日期的简写形式假定为该日期的午夜。 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 您或者需要定义一个时间戳以及日期,或者需要按第二天的以下内容过滤,小于等于或大于第二天的内容过滤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM