==================================
Table Name: tableName
Time Field name: theDate
==================================
DatePart Functions
Date |
Abbreviations |
Year |
Yy, yyyy |
Quarter |
Qq, q |
Month |
Mm, m |
Dayofyear |
Dy, y |
Day |
Dd, d |
Week |
Wk, ww |
Weekday |
Dw |
Hour |
Hh |
Minute |
Mi, n |
Second |
Ss, s |
Millisecond |
MS |
Query records of the current day
Select * from tableName where DATEPART (dd, theDate) = DATEPART (dd, GETDATE () and DATEPART (mm, theDate) = DATEPART (mm, GETDATE ()) and DATEPART (yy, theDate) = DATEPART (yy, GETDATE ())
Query records of this week
Select * from tableName where DATEPART (wk, theDate) = DATEPART (wk, GETDATE () and DATEPART (yy, theDate) = DATEPART (yy, GETDATE ())
Query records of this month
Select * from tableName where DATEPART (mm, theDate) = DATEPART (mm, GETDATE () and DATEPART (yy, theDate) = DATEPART (yy, GETDATE ())
Query this season's records
Select * from tableName where DATEPART (qq, theDate) = DATEPART (qq, GETDATE () and DATEPART (yy, theDate) = DATEPART (yy, GETDATE ())
Query records of the current year
Select * from tableName where DATEPART (yy, theDate) = DATEPART (yy, GETDATE ())
Specifically, GETDATE () is a function used to obtain the system time.
Certificate --------------------------------------------------------------------------------------------------------------------------------------------------
Datediff Function
Date |
Abbreviations |
Year |
Yy, yyyy |
Quarter |
Qq, q |
Month |
Mm, m |
Dayofyear |
Dy, y |
Day |
Dd, d |
Week |
Wk, ww |
Hour |
Hh |
Minute |
Mi, n |
Second |
Ss, s |
Millisecond |
MS |
Query records of the current day
Select count (*) from tableName where (DATEDIFF (dd, theDate, GETDATE () = 0)
Query records of this week
Select count (*) from tableName where (DATEDIFF (wk, theDate, GETDATE () = 0)
Query records of this month
Select count (*) from tableName where (DATEDIFF (mm, theDate, GETDATE () = 0)
Query this season's records
Select count (*) from tableName where (DATEDIFF (qq, theDate, GETDATE () = 0)
Query records of the current year
Select count (*) from tableName where (DATEDIFF (yy, theDate, GETDATE () = 0)
Article: http://blog.csdn.net/coolwzjcool/archive/2007/08/25/1758470.aspx