Use the following script to get time difference in hours, minutes, seconds and milliseconds in SQL Server.
-- Declare the Start and End date DECLARE @SDATE AS DATETIME TART_DATE AS DATETIME DECLARE @END_-- Set Start and End date SET @START_DATE = GETDATE() SET @END_DATE = DATEADD(SECOND, 3910, GETDATE()) -- Get the Result in HH:MI:SS:MMM(24H) format SELECT CONVERT(VARCHAR(12), DATEADD(MS, DATEDIFF(MS, @START_DATE, @END_DATE), 0), 114) AS TimeDiff
— Result in HH:MI:SS:MMM(24H) format
————-
TimeDiff
————-
01:05:10:000
Just modify theĀ Start and End date parameters above as per your requirements and you will get the respective time difference.
I hope this helps as it helped me. Happy coding ![]() |