how to add time

Cholotron 161 Reputation points

Good Morning,

I have two fields
tran_in (deatetime) = "2020-09-21 15:42:39.000"
tran_desc2 (char(30)) = "00:03:59"

I need to add these two fields

Thank you !!!

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,517 questions
0 comments No comments
{count} votes

Accepted answer
  1. Tom Cooper 8,461 Reputation points
    Declare @Sample Table(tran_in datetime, tran_desc2 char(30));  
    Insert @Sample(tran_in, tran_desc2) Values('2020-09-21 15:42:39.000', '00:03:59')  
    Select tran_in, tran_desc2, DateAdd(second, DateDiff(second, '19000101', tran_desc2), tran_in) As SummedDate  
    From @Sample;  


    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Viorel 109.9K Reputation points

    Check a sample:

    declare @example as table ( tran_in datetime, tran_desc2 char(30) )
    insert into @example values ( '2020-09-21 15:42:39.000', '00:03:59' )
    select *,
        tran_in + tran_desc2
    from @example
    2 people found this answer helpful.