简体   繁体   English

如果选择的日期等于或大于数据中的日期,则日期之间的查询仅返回结果

[英]Query between dates only returns results if a selected date is equal or greater than date in data

I have two queries that are using a between clause to produce a date range, where the date is passed in through a VB.net program: 我有两个查询,它们使用ween子句来生成日期范围,该日期范围是通过VB.net程序传递的:

select
 w.plate,
 Description,
 Date_in,
 time_in,
 Date_out,
 Time_out,
 Date_out-Date_in as "Days on Site",
 Time_out-Time_in as "Duration on Site (Hrs)"
from tbl_stay S
inner join tblwhitelist W
on S.plate=W.plate
where Date_in between "1/06/2013" and "25/09/2013"

and

select
Plate,
Date_in,
Time_in,
Date_out,
Time_out,
Date_out-Date_in as "Days on site",
Time_out-Time_in as "Duration on site (Hrs)"
from tbl_stay
where plate not in (Select plate from tblwhitelist)
and date_in between "1/07/2013" and "1/08/2013"

For testing, i have a block of data that has the date "25/07/2013" for both in and out. 为了进行测试,我输入和输出的日期均为“ 25/07/2013”​​。 These queries only seem to produce results if the day of the month is greater than the day mentioned in the data (25) 仅当月份中的某天大于数据中提到的日期时 ,这些查询才会产生结果(25)

for example: the dates mentioned in the queries above: 例如:上面查询中提到的日期:

Date_in between "1/06/2013" and "25/09/2013"

will yield a result, however 将产生结果,但是

date_in between "1/07/2013" and "1/08/2013"

will not. 将不会。 even though the date included in the test data (25/07/2013) is within both of these ranges. 即使测试数据中包含的日期(2013年7月25日)在这两个范围内。

I am completely stumped. 我完全陷入了困境。 What could possibly be going on here? 这可能是怎么回事? any assistance would be appreciated 任何援助将不胜感激

When you use double quotes you are comparing text-strings , not dates . 使用双引号时,您将比较text-strings ,而不是dates Literal meaning of 01/07/2013 is less than 25/01/2013 , basically these strings are compared character by character. 01/07/2013字面意义小于25/01/2013 ,基本上这些字符串是逐字符比较的。 If you look at the first character in both strings, then 0 is less than 2 . 如果您查看两个字符串中的第一个字符,则0小于2

The answer is not to use Between. 答案是不使用之间。

Separate that line in the WHERE clause into two and explicitly specify whether or not to include that date by using a >= or just a > . 分离该行中WHERE子句为两个和明确指定是否通过使用包括该日期>= ,或只是一个>

AND date_in > "1/07/2013" or date_in >= "1/07/2013" AND date_in > "1/07/2013"date_in >= "1/07/2013"

AND date_in < "1/08/2013" or date_in <= "1/08/2013" AND date_in < "1/08/2013"date_in <= "1/08/2013"

暂无
暂无

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

相关问题 查询多个日期,不大于当前日期 - Query multiple dates NOT greater than the current date 获取的数据大于等于今天的日期 - get the data is greater than is equal todays date 如果所选日期在两个日期之间,如何从查询中获取结果? - How to get results from the query if the selected date is between two dates? 如果添加日期和当前日期之间的持续时间不大于或等于 2 小时,则获取数据 - Fetch a data if the time duration between added date and current date is not greater than or equal to 2 hours MySQL查询返回等于或大于特定日期的行,其中日期以年,月和日列分隔 - MySQL query to return rows that are equal to or greater than a certain date, where the date is separated in year, month and day columns MySQL查询以选择日期,其中字段为NULL或字段日期值不大于另一个日期 - MySQL query to select dates where field is NULL or field date value is not greater than another date MySQL日期大于返回所有行 - MySQL date greater than returns all rows 所选日期之间的1年中的任何日期MYSQL查询 - Any date 1 year from between selected dates MYSQL query Mysql选择大于或等于今天的最近项,但仅限于一个日期 - Mysql Select Recent items greater than or equal to today but limit to one date only SQL Select查询以选择截止日期之间的数据,其中起始日期月份大于截止日期月份,年份差&gt; 1 - SQL Select query to select data between to dates where from date month is higher than the to date month and year difference is >1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM