J
J
Joker4562017-09-26 19:09:41
SQL
Joker456, 2017-09-26 19:09:41

How to display records in the timezone from evening to morning of the next day?

Good night everyone, I broke my head, I can’t make a sql query that works with the smalldata type, i.e. 00:00:00 - 23:59:59.
It is necessary to display records in the range from 17:31 to 07:29 (of the next day)
Table columns: TimeFrom, TimeTo ...
SELECT ID, Name, TimeFrom, TimeTo FROM Table WHERE ('17:35:00' BETWEEN TimeFrom and TimeTo)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Holub, 2017-09-26
@denman1985

I somehow poorly understood how everything is stored there and what should be displayed.
If the data in the table can be stored in the form:
TimeFrom, TimeTo
1. 17:31:00, 07:29:00
2. 20:34:00, 04:40:00
3. 23:00:00, 07:45: 00
4. 12:00:00, 15:00:00
5. 18:00:00, 23:00:00
, and records like lines 1, 2, 5 should be displayed:

SELECT ID, Название, ВремяОт, ВремяДо 
FROM Table 
WHERE (ВремяОт > ВремяДо and ВремяОт >= '17:31:00' and ВремяДо <= '07:29:00') /* для обработки 1 и 2 строки */
or (ВремяОт < ВремяДо and (( ВремяОт >= '17:31:00' and ВремяДо <= '23:59:59'  ) or ( ВремяОт >= '00:00:00' and ВремяДо <= '07:29:00'  )) /* для обработки 5й строки */

J
Joker456, 2017-09-27
@Joker456

Ideal for all occasions.

SELECT ID, Название, ВремяОт, ВремяДо 
FROM Table
WHERE (ВремяОт > ВремяДо or ВремяОт > '21:30:00' and ВремяДо < '21:30:00')
or '21:30:00' BETWEEN ВремяОт and ВремяДо

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question