Sql server 在Microsoft SQL数据库上筛选日期
我目前正在使用过滤器,根据今天的日期介于起始日期和截止日期之间的日期从表中筛选出数据。并且当前使用where条件作为Sql server 在Microsoft SQL数据库上筛选日期,sql-server,Sql Server,我目前正在使用过滤器,根据今天的日期介于起始日期和截止日期之间的日期从表中筛选出数据。并且当前使用where条件作为 Select * FROM [Snapshot].[dbo].[ABCVIEW] where (getdate() >= fromdate and (todate = '1900-01-01 00:00:00.000')) or getdate() between fromdate and todate 还有todate,它在使用任何筛选器之前也有今天的日期 但是我使用
Select * FROM [Snapshot].[dbo].[ABCVIEW] where (getdate() >= fromdate and (todate = '1900-01-01 00:00:00.000')) or getdate() between fromdate and todate
还有todate,它在使用任何筛选器之前也有今天的日期
但是我使用的过滤器无法看到todate=2016-05-31 00:00:00.000。我试图补充
todate<= getdate()
todategetdate返回的当前时间大于2016-05-31 00:00:00.000
因此,如果要包含昨晚午夜,请从getdate()中减去1:
如果您转换为日期,则只会得到日期
SELECT Convert(date, getdate())
所以你可以用
.......
CONVERT( Date, fromDate) and CONVERT(Date, DateAdd( d, 1, toDate))
请用通俗易懂的英语解释您希望标准返回的内容。
.......
CONVERT( Date, fromDate) and CONVERT(Date, DateAdd( d, 1, toDate))