How to query between date and specific time range

38
April 16, 2019, at 03:30 AM

I need help on a query between date and specific time range. For example, a user entering the building from 1 Jan 2019 until 1 April 2019 and only from 7 PM until 10 PM for that date.

the database stored EVENTDATE as 01.01.2019, 07:15:01.000

I have tried per day and works

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

tried by date range and didn't works

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'
Answer 1

You can convert the date to time first before adding a condition.

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'
Answer 2

I suspect you just need to use correct formats for the date/time values:

SELECT e.*
FROM event e
WHERE e.eventdate BETWEEN '2019-01-01 19:00:00' AND '2019-01-01 22:00:00'
READ ALSO
How to invert or filter out the two employees that work on projects in other departments?

How to invert or filter out the two employees that work on projects in other departments?

So right now I am so close but right now the result table that is return only shows the employees that I don't want to see and I want to show the employees that only work on projects within their department

25
Is there a way to hide all database info such as password, username, etc?

Is there a way to hide all database info such as password, username, etc?

I'm creating several php scriptsMust I always insert the host, username, password, etc

31
SQL filter out ids that have multiple values

SQL filter out ids that have multiple values

I have MySQL table in the following format

32
How I skip one cell in MySQL query

How I skip one cell in MySQL query

I'm trying to make PHP code update column called "downloads" to zero inside MySQL

16