Question: I have two variables `@date` of type `datetime` and `@time` of type `time`. I want to add both to get another `datetime` variable. And I want to perform further calculations on it.

Ex: 

```
Declare @date datetime
Declare @time time

```

I want something like this

```
@date = @date + @time (but not concatenation)

SELECT @Startdate = DATEADD(DAY, -1, @date )

```

Is there any way?

Answer: 
If you need to take only date part from `@date` and time part from `@time` - can convert your `@date` and `@time` to strings, concatenate the values and convert back to datetime:

```
select cast(convert(nvarchar(20), @date, 104) + ' ' +
            convert(nvarchar(20), @time, 108) as datetime2)

```

Or, alternatively, if you need to add time to datetime value, you can do something like:

```
select dateadd(ms, 
           datepart(ms, @time), 
           dateadd(ss, 
                   datepart(ss, @time), 
                   dateadd(mi, 
                           datepart(mi, @time), 
                           dateadd(hh, datepart(hh, @time), @date))))

```
Your code is correct.

```
DECLARE @date DATETIME = '1/1/2020'
DECLARE @time TIME = '1:00 pm'
DECLARE @Startdate DATETIME

SET @date = @date + @time

SELECT @Startdate = DATEADD(DAY, -1, @date)

@date = 2020-01-01 13:00:00.000
@Startdate = 2019-12-31 13:00:00.000

```

It isn't concatenating, it is adding them together. The time on @date is 0:00:00.000, so it might appear to be concatenating them. But change @date to '1/1/2020 1:00 am' and then:

```
@date = 2020-01-01 14:00:00.000
@Startdate = 2019-12-31 14:00:00.000

```