在Sql Server 2012中进行日期比较的SQL查询

时间:2021-01-23 23:38:56

I want to fetch all records from table which are 15 days old. I have found a solution in MySql:

我想从15天以上的表中获取所有记录。我在MySql中找到了一个解决方案:

select * 
from dt_tb 
where dt >= DATE_SUB(CURDATE(), INTERVAL 15 DAY); 

What its equivalent in SqlServer?

它在SqlServer中的等价物是什么?

1 个解决方案

#1


3  

SELECT *
FROM dbo.YourTable
WHERE dt >= DATEADD(DAY,-15,GETDATE())

If you want the whole day without worrying about the time part:

如果你想要一整天而不用担心时间部分:

SELECT *
FROM dbo.YourTable
WHERE dt >= DATEADD(DAY,-15,CAST(GETDATE() AS DATE))

#1


3  

SELECT *
FROM dbo.YourTable
WHERE dt >= DATEADD(DAY,-15,GETDATE())

If you want the whole day without worrying about the time part:

如果你想要一整天而不用担心时间部分:

SELECT *
FROM dbo.YourTable
WHERE dt >= DATEADD(DAY,-15,CAST(GETDATE() AS DATE))