Set time portion of a datetime variable

This will also work:

DECLARE @start_date datetime
DECLARE @end_date datetime

SET @start_date = LEFT(CONVERT(nvarchar, DATEADD(DAY, -2, GETDATE()), 120), 11) + N'20:00:00'
SET @end_date = @start_date + 1

select @start_date, @end_date

Although cyberkiwi's answer is very clever! =)


DECLARE @start_date DATETIME
DECLARE @end_date DATETIME

SET @start_date = DATEADD(hour, 20, DATEDIFF(DAY, 2, GETDATE()))
SET @end_date = @start_date + 1

select @start_date, @end_date

I needed to pull a date from the database and append 3:00 Pm to it. I did it this way

select dateadd(hour, 15, datediff(day, 0, myDatabaseDate)) 
from dbo.myDatabaseTable
where myDatabaseId = 1

The result that it returned was 2017-10-01 15:00:00.000. The date in the database is 2017-10-01. The solution that I proposed was to keep my current date. I added 0 days to my existing date. I gave it 15:00 hours and it worked like a charm.