1. 程式人生 > >SQL Server 取前一天的0點和23點59分59秒

SQL Server 取前一天的0點和23點59分59秒

nbsp getdate etime sel end bsp detail add sele

DECLARE @startDate1 DATE;
DECLARE @startDate DATETIME;
SET @startDate1=GETDATE();SELECT @startDate=DATEADD(DAY,-1,@startDate1);
DECLARE @endDate DATETIME ;SET @endDate=DATEADD(second,-1,CONVERT(DATETIME,@startDate1));
SELECT @startDate startDate,@endDate endDate;

startDate endDate

----------------------- -----------------------
2014-05-19 00:00:00.000 2014-05-19 23:59:59.000

SQL Server 取前一天的0點和23點59分59秒