Prerequisites: Assume that the table name is: TableName; the Time field is named: thedate
① query this week's records
SELECT * from TableName where DATEPART (wk, thedate) = DATEPART (wk, GETDATE ()) and DATEPART (yy, thedate) = DATEPART (yy, GET DATE ())
② Check this month's record
SELECT * from TableName where DATEPART (mm, thedate) = DATEPART (mm, GETDATE ()) and DATEPART (yy, thedate) = DATEPART (yy, GET DATE ())
③ check the records for this season
SELECT * from TableName where DATEPART (QQ, thedate) = DATEPART (QQ, GETDATE ()) and DATEPART (yy, thedate) = DATEPART (yy, GET DATE ())
Select DateDiff (Day,dateadd (mm, DateDiff (mm, "", GETDATE ()), ""), DateAdd (mm, DateDiff (mm, "", GETDATE ()), " 1900-02-01 "))
④ query for common statements recorded this month
SELECT * from [table name] WHERE (DATEPART (mm, date) = @month) and (DATEPART (yy, date) = @year)
This week: SELECT * FROM table where DATEDIFF (Week,c_calltime,getdate ()) =0--c_calltime as Date field
This month: SELECT * FROM table where DATEDIFF (Month,c_calltime,getdate ()) =0--c_calltime as Date field
This season: SELECT * from table where DATEDIFF (Qq,c_calltime,getdate ()) =0
First half year 1-6, after half year 7-12:select * from table where DATEPART (mm,c_calltime)/7 = datepart (Mm,getdate ())/7
SQL gets statements for this week, this month, and this quarter's records