aes*_*nae 1 sql datetime rounding date-range
我想限制报告从日期A到日期B返回记录.这就是我一直在做的事情:
declare @startDate varchar(20)
declare @endDate varchar(20)
set @startDate = '01/01/2008'
set @endDate = '04/01/2008'
-- test what are the start and end dates
select min(date),max(date) from view_Inspections
where date between @startDate and @endDate
Run Code Online (Sandbox Code Playgroud)
...我被告知从1月1日上午12点到3月31日晚上11:59返回记录(当没有时间指示时,午夜是默认值).但是我注意到了一个差异,即如果记录的时间为00:00:00,那么它将成为该集合的一部分.
有没有更准确的方法这样做,它将准确返回我想要的日期范围?*
我试过用时间:
declare @startDate varchar(20)
declare @endDate varchar(20)
set @startDate = '01/01/2008 00:00:00'
set @endDate = '04/01/2008 11:59:59'
-- test what are the start and end dates
select min(date),max(date) from view_Inspections
where date between @startDate and @endDate
Run Code Online (Sandbox Code Playgroud)
...但是我注意到了一些不可思议的事情:SQL Server将把hundreth-second上升一半.如果我在11:59:29之后的任何时间使用,那么我得到了4月1日的记录(哈!愚人节的记录!grr).这是为什么?
总有简单的选择:
declare @startDate varchar(20)
declare @endDate varchar(20)
set @startDate = '01/01/2008'
set @endDate = '04/01/2008'
-- test what are the start and end dates
select min(date),max(date) from view_Inspections
where date >= @startDate
and date < @endDate
Run Code Online (Sandbox Code Playgroud)