0

我需要有关日期和特定时间范围之间查询的帮助。例如,用户在该日期从晚上 7 点1 Jan 2019到晚上10 点进入大楼。1 April 2019

数据库将 EVENTDATE 存储为 01.01.2019, 07:15:01.000

我每天都尝试过并且有效

SELECT *
FROM event
WHERE eventdate BETWEEN '01.01.2019, 19:00:00' AND '01.01.2019, 22:00:00'

按日期范围尝试但无效

SELECT *
FROM event
WHERE eventdate BETWEEN '01.01.2019' AND '01.02.2019'
  AND eventdate BETWEEN '19:00:00.000' AND '22:00:00.000'
4

2 回答 2

0

我怀疑您只需要为日期/时间值使用正确的格式:

SELECT e.*
FROM event e
WHERE e.eventdate BETWEEN '2019-01-01 19:00:00' AND '2019-01-01 22:00:00'
于 2019-04-15T01:55:08.990 回答
0

您可以在添加条件之前先将日期转换为时间。

SELECT *
FROM event
WHERE eventdate BETWEEN '01.01.2019' AND '01.02.2019'
  AND time(eventdate) BETWEEN '19:00:00.000' AND '22:00:00.000'
于 2019-04-15T01:58:51.800 回答