从SQL Server中的日期字段中减去

时间:2022-12-04 01:25:32

I have a field receiveddate which is a datetime data type. I am trying to return results 7 days back from that date. So basically I want to see anything with a received date of today back 7 days. I tried several things including c.ReceivedDate BETWEEN DATEADD(dd,-7, GETDATE()) AND getdate() but its pulling results from 2011! Im using SQL Server 2008. Any suggestions?

我有一个字段receivedate,它是一个日期时间数据类型。我试图从那天起7天后返回结果。所以基本上我希望看​​到任何收到日期为7天的东西。我尝试了几个东西,包括c.ReceivedDate BETWEEN DATEADD(dd,-7,GETDATE())和getdate(),但它从2011年开始拉动!我正在使用SQL Server 2008.有什么建议吗?

1 个解决方案

#1


0  

you code should be

你的代码应该是

c.ReceivedDate BETWEEN (GETDATE() - 7) AND GETDATE()

#1


0  

you code should be

你的代码应该是

c.ReceivedDate BETWEEN (GETDATE() - 7) AND GETDATE()