SQL Statement - condition in state?

I have a table where each record contains a time represented by a hour column (int)

and a minute column (int)

. For example:

**records |hours| mins**
record1 |  15 |  30
record2 |  12 |  25

      

I want to write a statement that only displays records that are earlier than the current time. So far I have had:

SELECT... 

WHERE hours >= hour(current_time)
AND
mins >= minute(current_time)
AND...

      

But that doesn't work because the hours and minutes must be greater than the current hours and minutes. How should I write so that if the hours are the same the minutes are compared?

+3


source to share


2 answers


Do something like this:



WHERE  hours >= hour(current_time)
OR  (hours = hour(current_time) AND mins >= minute(currentime))

      

+3


source


Something like



Where hours * 60 + mins > hours(currentTime) * 60 + minute(currentTime)

      

0


source







All Articles