Wishy
Wishy

Reputation: 39

MySQL search between date, but also between time ranges

I have a table with datetime like this:

2018-08-08 00:00:00
2018-08-08 03:00:00
2018-08-08 06:00:00
2018-08-08 09:00:00
2018-08-08 12:00:00
2018-08-08 15:00:00
2018-08-08 18:00:00
2018-08-08 21:00:00
2018-08-09 00:00:00
2018-08-09 03:00:00
2018-08-09 06:00:00
2018-08-09 09:00:00
2018-08-09 12:00:00

I search for rows between CURDATE() + INTERVAL 1 DAY and CURDATE() + INTERVAL 4 DAY, but also only at 06:00:00 and 12:00:00.

How can I select this hours?

Regards Wishy

Upvotes: 0

Views: 35

Answers (1)

sticky bit
sticky bit

Reputation: 37472

You can use time() to extract the time.

...
WHERE ...
      AND time(nmuloc) BETWEEN time '6:00:00'
                               AND time '12:00:00'
...

Upvotes: 1

Related Questions