Get Hours and Minutes Between a Date and Now in SQL Server
sqlSQLtipssql-serverdatetime
Split the time elapsed since a given date and time into whole hours and the remaining minutes, using DATEDIFF with / 60 and % 60.
SELECT
CASE
WHEN DATEDIFF(MINUTE, '2020-12-18 10:52:12', GETDATE()) / 60 > 0
THEN DATEDIFF(MINUTE, '2020-12-18 10:52:12', GETDATE()) / 60
ELSE ''
END AS Hr,
DATEDIFF(MINUTE, '2020-12-18 10:52:12', GETDATE()) % 60 AS [min];
-- Example result, 5 hours and 4 minutes after the date above:
-- Hr | min
-- 5 | 4
Comments
Loading comments…