Calculate time difference in minutes in SQL Server

prabu R picture prabu R · Nov 18, 2014 · Viewed 170.3k times · Source

I need the time difference between two times in minutes. I am having the start time and end time as shown below:

start time | End Time    
11:15:00   | 13:15:00    
10:45:00   | 18:59:00

I need the output for first row as 45,60,15 which corresponds to the time difference between 11:15 and 12:00, 12:00 and 13:00, 13:00 and 13:15 respectively.

Answer

Veera picture Veera · Nov 18, 2014

Use DateDiff with MINUTE difference:

SELECT DATEDIFF(MINUTE, '11:10:10' , '11:20:00') AS MinuteDiff

Query that may help you:

SELECT StartTime, EndTime, DATEDIFF(MINUTE, StartTime , EndTime) AS MinuteDiff 
FROM TableName