Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I compare only hour and minute in sql

I have a column stop_execution_date in sysjobactivity table. I need to get details of job only which ran after 4:10 AM.

I tried it using

    cast(DATEPART(hour, sja.stop_execution_date) as varchar)+cast(DATEPART(minute, sja.stop_execution_date) as varchar) >410

But, if job completes at 9:05 AM it is not accepting because datepart(hour) is 9 and datepart(minute) is 5. By using + we are getting 95 instead of 905, which is less then 410.

Can you please suggest me a good way to do that.

like image 341
user3749816 Avatar asked Sep 04 '14 16:09

user3749816


People also ask

How do I subtract hours and minutes in SQL Server?

Time subtraction: result = time1 - time2 If MINUTE( TIME2 ) <= MINUTE( TIME1 ) then MINUTE( RESULT ) = MINUTE( TIME1 ) - MINUTE( TIME2 ) . If MINUTE( TIME2 ) > MINUTE( TIME1 ) then MINUTE( RESULT ) = 60 + MINUTE( TIME1 ) - MINUTE( TIME2 ) and HOUR( TIME2 ) is incremented by 1.

How do I select minutes in SQL?

MySQL MINUTE() Function The MINUTE() function returns the minute part of a time/datetime (from 0 to 59).


2 Answers

How about:

(DATEPART(hour, sja.stop_execution_date) = 4 and (DATEPART(minute, sja.stop_execution_date) > 10)
OR DATEPART(hour, sja.stop_execution_date) > 4
like image 172
BeaglesEnd Avatar answered Sep 28 '22 06:09

BeaglesEnd


Could cast as a time.

cast(sja.stop_execution_date as time) > '04:10:00.0000000'
like image 33
SQLChao Avatar answered Sep 28 '22 06:09

SQLChao