That day:
SELECT * from T_news where DateDiff (Day,addtime,getdate ()) =0
Last three days:
SELECT * from T_news where DateDiff (Day,addtime,getdate ()) <= 2 and DateDiff (Day,addtime,getdate ()) >= 0
Week:
SELECT * from T_news WHERE (DATEPART (wk, addtime) = DATEPART (wk, GETDATE ())) and (DATEPART (yy, addtime) = DATEPART (yy, GET DATE ()))
Note: You cannot use the DateDiff difference at this time as 7, because DateDiff only represents the number of intervals
Month:
SELECT * from T_news WHERE (DATEPART (yy, addtime) = DATEPART (yy, GETDATE ())) and (DATEPART (mm, addtime) = DATEPART (mm, GET DATE ()))
Last one months:
SELECT * from T_news WHERE (DATEPART (yy, addtime) = DATEPART (yy, GETDATE ()))
and ((DATEPART (mm, addtime) = DATEPART (mm, GETDATE ())) OR (31-datepart (dd,addtime) +datepart (DD, GETDATE ())) <=31)
This quarter:
SELECT * from T_news where DATEPART (QQ, addtime) = DATEPART (QQ, GETDATE ()) and DATEPART (yy, addtime) = DATEPART (yy, Getdat E ())
SQL Server queries the current day, last three days, this week, this month, the last one months, the data for this quarter's SQL statement