寻找24小时间隔的时间窗

时间:2017-11-10 03:06:49

标签: sql-server sql-server-2012

我在SQL Server 2012中执行以下查询

print dateadd(day,datediff(day,1,getdate()),0)
print dateadd(day,datediff(day,0,getdate()),0)

并低于结果

Nov  9 2017 12:00AM
Nov 10 2017 12:00AM

但我正在寻找下面的结果

Nov  9 2017 12:00AM
Nov  10 2017 11:59PM

请帮助!!

1 个答案:

答案 0 :(得分:1)

你似乎想要:

print cast(getdate() as date);
print dateadd(minute, -1, dateadd(day, 2, cast(getdate() as date)))

或者,或者:

print cast(getdate() as date);
print dateadd(minute, 2*24*60-1, cast(getdate() as date))