Question:

What is the TIME BETWEEN format in sql? (to see the diff. of 2 times)?

by Guest44565  |  earlier

0 LIKES UnLike

What is the TIME BETWEEN format in sql? (to see the diff. of 2 times)?

 Tags:

   Report

1 ANSWERS


  1. There are several possibilities, here are some examples...

    --- Date Time Calculations

    DECLARE @Date1  as datetime

    DECLARE @Date2  as datetime

    DECLARE @Time1  as varchar(10)

    DECLARE @Time2  as varchar(10)

    SET @Date1 = '2008-01-01 07:00:00'

    SET @Date2 = '2008-01-05 08:30:00'

    SET @Time1 = '01:20:30'

    SET @Time2 = '00:41:31'

    -- Difference between two datetimes, shown as hh:mm:ss...

    SELECT CONVERT(VARCHAR(8), DATEADD(SECOND, DATEDIFF(SECOND, @Date1, @Date2), '19000101'), 8)

    -- Adding a varchar time to a datetime...

    SELECT @Date1 + Cast(@Time1 as datetime)

    -- Adding two varchar times together...

    SELECT CONVERT(VARCHAR(8), Cast(@Time1 as datetime) + Cast(@Time2 as datetime), 8)

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.