Combining (concatenating) date and time into a datetime

后端 未结 12 950
夕颜
夕颜 2020-12-08 15:06

Using SQL Server 2008, this query works great:

select CAST(CollectionDate as DATE), CAST(CollectionTime as TIME)
from field

Gives me two co

12条回答
  •  执笔经年
    2020-12-08 15:11

    dealing with dates, dateadd must be used for precision

    declare @a DATE = getdate()
    declare @b time(7) = getdate()
    select @b, @A, GETDATE(), DATEADD(day, DATEDIFF(day, 0, @a), cast(@b as datetime2(0)))
    

提交回复
热议问题