如何在日期和特定时间范围之间查询

时间:2019-04-15 01:52:39

标签: mysql flamerobin

我需要有关日期和特定时间范围之间的查询的帮助。例如,某个用户从1 Jan 20191 April 2019进入建筑物,并且在该日期仅从 7PM 10PM

数据库将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'

2 个答案:

答案 0 :(得分:0)

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

SELECT e.*
FROM event e
WHERE e.eventdate BETWEEN '2019-01-01 19:00:00' AND '2019-01-01 22:00:00'

答案 1 :(得分: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'