Answer the question
In order to leave comments, you need to log in
How to implement SQL query on time?
I have a database with tables (id, start, end) .
These are the lessons, start is the beginning of the lesson end the end of the lesson (HH:MM:SS).
Now how to implement a selection to find out what lesson is now, if it is now, for example, 10:25. (+ find out how many minutes until the end of the lesson left). I don't really have any idea how to do it
Answer the question
In order to leave comments, you need to log in
Comparing with NOW() is not correct because NOW() is the current date + time . If time is stored in the table, use the CURRENT_TIME variable.
select
id,
title,
start,
end,
timediff(end, current_time) as remain_time
from lessons
where current_time between start and end
;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question