Showing posts with label datediff in hours and minutes in sql server. Show all posts
Showing posts with label datediff in hours and minutes in sql server. Show all posts

Thursday, June 23, 2016

Calculate hours minutes between two dates in SQL

In this article, I am going to create logic how to calculate hours and minute between two dates in SQL.

DECLARE @date1 DATETIME = '2016-06-23 12:18:03.133';
DECLARE @date2 DATETIME = getdate();
SELECT CAST((DATEDIFF(Minute, @date1, @date2)) / 60 AS VARCHAR(5)) + ' Hrs' + ' ' + RIGHT('0' + CAST((DATEDIFF(Minute, @date1, @date2)) % 60 AS VARCHAR(2)), 2) + ' Min' AS 'TotalTime'


Output