Table Name: tablename time field name: thedate ============================== datepart Function
| 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 this month. Select * From tablename where 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 this season's record select * From tablename where datepart (QQ, thedate) = datepart (QQ, getdate () and datepart (YY, thedate) = datepart (YY, getdate ())
Specifically, getdate () is a function used to obtain the system time.
Functions ------------------- 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 the current day's record select count (*) from tablename where (datediff (DD, thedate, getdate () = 0) query this month's record select count (*) from tablename where (datediff (mm, thedate, getdate () = 0) query this year's record select count (*) from tablename where (datediff (YY, thedate, getdate ()) = 0)
Source: http://www.bcbbs.net/news/Content.aspx? Id = 34330 Article Source: http://www.bcbbs.net/news/Content.aspx? Id = 34330
Table Name: tablename time field name: thedate
Query records of this month. Select * From tablename where 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 this season's record select * From tablename where datepart (QQ, thedate) = datepart (QQ, getdate () and datepart (YY, thedate) = datepart (YY, getdate ())
Specifically, getdate () is a function used to obtain the system time.