B
B
boomwest2015-08-28 13:39:36
MySQL
boomwest, 2015-08-28 13:39:36

How to select time from a range of cells in Mysql?

There are time_from cells and a time_to cell. (time format)
id from to
1 7:00:00 - 18:00:00
2 18:00:01 - 6:59:59
A query like
SELECT ... WHERE NOW() BETWEEN `time_from` AND `time_to`
works only for the case when NOW()<18:00
It is also impossible to manually make a query like
SELECT ... WHERE NOW() >time_from AND NOW < `time_to`
because 19:00 is greater than 6:59

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vlad Pasechnik, 2015-08-28
@boomwest

SELECT ... WHERE
(time_from < `time_to` AND NOW() > time_from AND NOW < `time_to`) OR
(time_from > `time_to` AND NOW() > time_from OR NOW < `time_to`)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question