1.获取前一天的 0点 和 23点59分59秒
DECLARE @startDate DATE,
@startDateTime DATETIME,
@endDate DATETIME
SET @startDate = GETDATE()
SELECT @startDateTime = DATEADD(DAY,-1,@startDate);
SET @endDate=DATEADD(second,-1,CONVERT(DATETIME, dateadd(dd,1,@startDateTime)))
SELECT @startDate startDate,@endDate endDate
startDate | endDate
2019-08-20 | 2019-08-19 23:59:59.000
2.获取当前的 0点 和 23点59分59秒
DECLARE @startDate DATE,
@startDateTime DATETIME,
@endDate DATETIME
SET @startDate = GETDATE()
SELECT @startDateTime = DATEADD(DAY,-1,@startDate);
SET @endDate=DATEADD(second,-1,CONVERT(DATETIME, dateadd(dd,1,@startDate)))
SELECT @startDate startDate,@endDate endDate
startDate | endDate
2019-08-20 | 2019-08-20 23:59:59.000