Home Forums SQL Server 2008 T-SQL (SS2K8) How to concatenate/convert date and time into a datetime? RE: How to concatenate/convert date and time into a datetime?

  • drew.allen (8/4/2015)


    Lynn Pettis (8/3/2015)


    Just another way to do it:

    declare @Date date = '20150803',

    @Time time = '15:00:00';

    select dateadd(second,datediff(second,0,@Time),cast(@Date as datetime))

    go

    I considered this approach, but discarded it, because the precision of the TIME datatype is smaller than a second, and I wasn't sure what precision the OP needed. This isn't a problem with DATE and DAY, because DAY is the smallest precision of a DATE field.

    Drew

    Then you change second to millisecond or what ever precision is necessary to capture the data appropriately. Just as you would change the cast from datetime to datetime2 if needed.