Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
597 B
1
Indexable
Never
DECLARE @StartDate DATETIME = '2023-07-30 02:00:00.156';
DECLARE @EndDate DATETIME = '2023-07-31 06:00:00.150';

DECLARE @TimeDifference INT = DATEDIFF(SECOND, @StartDate, @EndDate);
DECLARE @MillisecondsDifference INT = DATEDIFF(MILLISECOND, @StartDate, @EndDate) % 1000;

SELECT
    CONCAT(
        FLOOR(@TimeDifference / 3600), ':',
        RIGHT('00' + CAST((@TimeDifference % 3600) / 60 AS VARCHAR(2)), 2), ':',
        RIGHT('00' + CAST(@TimeDifference % 60 AS VARCHAR(2)), 2), ':',
        RIGHT('000' + CAST(@MillisecondsDifference AS VARCHAR(3)), 3)
    ) AS time_difference;