How to compare only date part when delivery date is today

后端 未结 5 594
既然无缘
既然无缘 2021-02-05 08:59

I\'m trying to create a report that gets records from a SQL Server database where the delivery date is today.

I\'ve tried

select * from (tablename)
where         


        
5条回答
  •  误落风尘
    2021-02-05 09:32

    I'd just create 2 params. One for StartTime and one for EndTime and use those in my query.

    DECLARE @StartTime DATETIME,
            @EndTime DATETIME 
    
    SET @StartTime = DATEDIFF(d,0,GETDATE())
    SET @EndTime = DATEADD(d,1,@StartTime)
    
    SELECT  *
    FROM    [tablename]
    WHERE   delivery_date >= @StartTime
            AND delivery_date < @EndTime
    

提交回复
热议问题