Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (55.6k points)

Can anyone tell me how to calculate time difference in hours and minutes in SQL Server?

1 Answer

0 votes
by (119k points)
edited by

We can be use CONVERT () function to calculate the time difference between two timestamps in hours and minutes.

Here is the example

Declare @Date_2 DATETIME = '2020-04-30 10:01:10.022'

Declare @Date_1 DATETIME = '2020-04-30 10:00:00.000'

Select CONVERT (TIME, @Date_2 - @Date_1) as Elapsed_Time

The output for the above query would be:

To become an SQL expert, you can register for for the best SQL courses by Intellipaat that offers instructor-led training, certification, and job assistance

Related questions

Browse Categories

...