SQL Server获取日期字段,如果少于3个月

时间:2021-06-11 15:41:55

I just need a where condition in my select statement where AddedDate is less than or within the 3 month backet. Like

我只需要在我的select语句中where where条件,其中AddedDate小于或在3个月的backet中。喜欢

Select * FROM My Table where AddedDate DateDiff of DateNow less than 3 months

3 个解决方案

#1


21  

Use DATEADD():

使用DATEADD():

Select * FROM My Table where AddedDate>=DATEADD(m, -3, GETDATE())

#2


5  

SELECT *
FROM   MyTable
WHERE  AddedDate >= DATEADD(month, -3, getdate())

#3


1  

not entirely sure that I understand but I think this is the function you need

不完全确定我理解,但我认为这是你需要的功能

where AddedDate >= dateadd(mm, -3,  getdate())

#1


21  

Use DATEADD():

使用DATEADD():

Select * FROM My Table where AddedDate>=DATEADD(m, -3, GETDATE())

#2


5  

SELECT *
FROM   MyTable
WHERE  AddedDate >= DATEADD(month, -3, getdate())

#3


1  

not entirely sure that I understand but I think this is the function you need

不完全确定我理解,但我认为这是你需要的功能

where AddedDate >= dateadd(mm, -3,  getdate())