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
The following dates are calculated for SQL:
Yesterday
Select CONVERT (varchar), GETDATE ()-1,120)
Tomorrow
Select CONVERT (varchar), GETDATE () + 1,120)
Last seven days
SELECT * from TB where Time field >= convert (varchar), GETDATE ()-7,120)
Next seven days
SELECT * from TB where Time field <= convert (varchar (ten), GETDATE () + 7,120) and Time field >= Time field
Last month
SELECT * FROM TB where month (time field) = Month (getdate ())-1
Month
SELECT * FROM TB where month (time field) = Month (getdate ())
Next month
SELECT * FROM TB where month (time field) = Month (getdate ()) + 1
If you are looking for an enquiry in the table:
--Yesterday
Select * from TableName Where DateDiff (DD, Datetimcol, GetDate ()) = 1
-Tomorrow
Select * from TableName Where DateDiff (DD, GetDate (), datetimcol) = 1
--Last seven days
Select * from TableName Where DateDiff (DD, Datetimcol, GetDate ()) <= 7
--Next seven days
Select * from TableName Where DateDiff (DD, GetDate (), Datetimcol) <= 7
--Last week
Select * from TableName Where DateDiff (wk, Datetimcol, GetDate ()) = 1
--This week
Select * from TableName Where DateDiff (wk, Datetimcol, GetDate ()) = 0
--Next week
Select * from TableName Where DateDiff (wk, GetDate (), datetimcol) = 1
--Last month
Select * from TableName Where DateDiff (mm, Datetimcol, GetDate ()) = 1
--This month
Select * from TableName Where DateDiff (mm, Datetimcol, GetDate ()) = 0
--Next month
Select * from TableName Where DateDiff (mm, GetDate (), datetimcol) = 1
>>> more
SQL statement gets this week, month, and year data