查询本日的记录 select * from tableName where DATEPART(dd, theDate) = DATEPART(dd, GETDATE()) and DATEPART(mm, theDate) = DATEPART(mm, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE()) 查询本月的记录 select * from tableName where DATEPART(mm, theDate) = DATEPART(mm, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE())
查询本周的记录 select * from tableName where DATEPART(wk, theDate) = DATEPART(wk, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE())
查询本季的记录 select * from tableName where DATEPART(qq, theDate) = DATEPART(qq, GETDATE()) and DATEPART(yy, theDate) = DATEPART(yy, GETDATE())
查询 n 天前的记录 select * from tableName where DATEDIFF(DAY,theDate,GETDATE())=n
查询 n 年前的记录 select * from tableName where DATEDIFF(Year,theDate,GETDATE())=n
查询 n 月前的记录 select * from tableName where DATEDIFF(Month,theDate,GETDATE())=n
=====================