Friday 9 August 2019

Get Difference between two dates as Minutes, Seconds, Hours in SQL Server

I am using the below query to get difference between two dates in Minutes, Seconds and Hours

DECLARE @mintime DATETIME = '2019-08-09 08:29:43.517'
DECLARE @maxtime DATETIME = getdate()
declare @minute int, @second int, @hour int
set @minute = datediff([minute], @minTime, @maxtime);
set @second = datediff([second], @minTime, @maxtime);
set @hour = datediff([hour], @minTime, @maxtime);
select @minute as [minute],@second as [second],@hour as [hour]