且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在日期时间字段中添加时间字段

更新时间:2023-02-15 15:41:10

尝试类似的方法。注意:我在这里不是毫秒级

  declare @dt datetime = getdate()
clarify @t time =' 01:35:45'

选择dateadd(second,
datepart(hour,@ t)* 3600 +
datepart(minute,@ t)* 60 +
datepart(second,@ t),
@dt)


I have to add time value to existing datetime value using T-SQL in SQL Server 2012.

I was thinking that DATEADD function it might be a solution, but it is not...

Perhaps I have somehow time convert to datetime?

So I have

StartDate 2013-02-18 18:34:40.330 (datetime)

Interval 00:11:00.0000000 (time)

EndDate ? tsql ? (datetime)

Any clue?

Try something like this. Note: I am not taking milliseconds here

declare @dt datetime = getdate()
declare @t time = '01:35:45'

select dateadd(second, 
                  datepart(hour,@t) * 3600 + 
                  datepart(minute,@t) * 60 + 
                  datepart(second,@t),
                  @dt)