Set time portion of a datetime variable

后端 未结 6 1034
慢半拍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:14

    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
    

提交回复
热议问题