Set time portion of a datetime variable

后端 未结 6 1035
慢半拍i
慢半拍i 2020-12-09 18:25

I am working on a query that will be an automated job. It needs to find all the transactions between 8 PM and 8 PM for the last day. I was thinking of doing something like

6条回答
  •  感情败类
    2020-12-09 19:02

    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! =)

提交回复
热议问题