No value is returned between operators if the dates are equal

I have a table called Productsinside this table. I have three entries:

ID | Price | Date
 1   20.0    2018-04-03 18:30:00
 2   30.00   2018-04-03 18:30:00
 3   30.00   2018-04-04 18:30:00

I want to return all records that have an Dateinterval between 2018-04-01(start date) and 2018-04-03(end date). The end result will be (id): 1,2.

My request has this syntax:

SELECT * FROM Products WHERE datetime BETWEEN '2018-04-03' AND '2018-04-03'

When I execute it inside the utility DB Browser for Slite, I get this message:

0 rows returned in 0ms from: SELECT * FROM Products WHERE datetime BETWEEN '2018-04-03' AND '2018-04-03'

But if I edit the request in:

SELECT * FROM Products WHERE datetime BETWEEN '2018-04-03' AND '2018-04-04'

I get the correct recording identifiers: 2, 3.

Is this a mistake, or did I do something wrong?

+4
source share
3 answers

- . , :

SELECT p.*
FROM Products p
WHERE datetime >= '2018-04-03' AND datetime < '2018-04-04';

2018-04-03.

between /. , - . , . SQL Server, .

+2

, , , , BETWEEN, :

SELECT *
FROM Products 
WHERE datetime BETWEEN '2018-04-03 00:00:00' AND '2018-04-03 23:59:59';

BETWEEN , 2018 , .

+1
SELECT * FROM Products WHERE cast(datetime as date) BETWEEN '2018-04-03' AND '2018-04-03'
-1

Source: https://habr.com/ru/post/1695695/


All Articles