Skip to content
Advertisement

How to compare time in mysql

I have a column of Time data type in mysql. I want to compare the time with a time string but don’t know how to compare it. e.g., I want to know that some specific time is greater than 10:30:00. How can I check it? I have this query but it is not showing any result although the data is available. what I am doing wrong?

select PK, userID, lr.Date, lr.Time, Half, lr.InOut, Op_UserID, About
from loginrecord lr
where lr.Date Between '2017-05-17' AND '2017-05-17'
and lr.InOut = 1
and lr.Time > '10:30:00'

Advertisement

Answer

You can use the TIME_FORMAT function, like this:

select PK, userID, lr.Date, lr.Time, Half, lr.InOut, Op_UserID, About
from loginrecord lr
where lr.Date Between '2017-05-17' AND '2017-05-17'
and lr.InOut = 1
and TIME_FORMAT(lr.Time, '%H:%i') > '10:30'
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement