Question : T-SQL:update only time in a date field from another column value

I need the code to update a dates column time without changing the date.
The required time is stored in another column in small date time data type.

I got the below code from MSDN(it works) but am spending too much time trying to edit the code to fit my requirement.

How can i set the @d1 to equal the date field i want to change and @t1 as the new date.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
use map
declare @d1 datetime
declare @t1 datetime

set @d1 = '1/2/1934 03:14:18.000'
set @t1 = '1/2/1934 03:14:18.000'

declare @dCombo datetime
set @dCombo = DateAdd(dd, DateDiff(dd, @t1, @d1), @t1)

SELECT @dCombo

Answer : T-SQL:update only time in a date field from another column value

UPDATE yourtable
   SET your_date_field = DateAdd(dd, DateDiff(dd, STARTTIME, your_date_field ), STARTTIME)
WHERE ...
Random Solutions  
 
programming4us programming4us