简体   繁体   English

在两个日期之间从数据库中选择行会导致错误的结果

[英]selecting rows from database between two dates giving wrong results

Selecting rows from database between two dates giving wrong results, the below query not working for me. 从两个日期之间的数据库中选择行会导致错误的结果,以下查询对我不起作用。 I tried some answers, but this one not giving the correct results.I think, i am missing somewhere. 我尝试了一些答案,但是这个答案没有给出正确的结果。我想,我在某个地方不见了。

SELECT * FROM Table WHERE Date BETWEEN '07/10/2015' AND  '07/14/2015'

changed to 变成

SELECT * FROM Table WHERE Date BETWEEN '07-10-2015' AND  '07-14-2015'

still not working! 还是行不通!

Use the default date format YYYY-MM-DD 使用默认的日期格式YYYY-MM-DD

SELECT * FROM your_Table 
WHERE Date BETWEEN '2015-07-10' AND  '2015-07-14'

That's right, you can not use BETWEEN statement when the data type format is not a DATE or DATETIME , you must change the data type first. 没错,当数据类型格式不是DATEDATETIME ,不能使用BETWEEN语句,必须先更改数据类型。

BTW I just realized that even data type is a DATE/DATETIME format you can't use / in the SQL statement itself when using MySQL, versus SQL you can use / when the column data type is DATE/DATETIME . 顺便说一句,我刚刚意识到即使数据类型是DATE/DATETIME格式,在使用MySQL时,SQL语句本身也不能使用/ ;而对于SQL,当列数据类型是DATE/DATETIME时,您可以使用/ Just correct me if I'm wrong... 如果我错了就纠正我...

Erm, you're searching on "Date" but are you meant to be searching on "CreateDate"? 嗯,您正在搜索“日期”,但您是要在“创建日期”上搜索吗? That's what your image shows. 这就是您的图像所显示的。

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

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