Transferred from: http://www.cnblogs.com/likwo/archive/2010/04/16/1713282.htmlQuery Day:SELECT * FROM table where to_days (column_time) = To_days (now ());SELECT * FROM table where date (column_time) = Curdate ();Query one week:SELECT * FROM table
Query Day:Select * from Table where = To_days (now ()); Select * from Table where =Query one week:Select * from Table where 7 Day Date (column_time);Query one months:Select * from Table where 1 MONTH Date (column_time);MySQL date and time
Today took time to collate a MySQL in the days, weeks, months of time data related to the SQL statement of the various writing, part of the collection of information, all hand-finishing, their own learning at the same time, share to everyone, and
To create a table:The code is as follows:CREATE table if not exists t(ID int,Addtime datetime default ' 0000-00-00 00:00:00′)Add two initial data:Insert T VALUES (1, ' 2012-07-12 21:00:00′);Insert T VALUES (2, ' 2012-07-22 21:00:00′);Data inserted
To create a table:
Copy Code code as follows:
CREATE table if not exists t
(
ID int,
Addtime datetime default ' 0000-00-00 00:00:00′
)
Add two initial data:
Insert T VALUES (1, ' 2012-07-12 21:00:00′);Insert T
Today took time to collate a MySQL in the days, weeks, months of time data related to the SQL statement of the various writing, part of the collection of information, all hand-finishing, their own learning at the same time, share to everyone, and
Thank you: http://www.111cn.net/database/110/d45124323da8d2d87b80f78319987eda.htmView another blog on the same topic: http://blog.csdn.net/cleanfield/article/details/41447585----------------------------------------------------------------------------
I. Annual ENQUIRY Enquiry data for the yearSELECT * fromblog_articleWHERE Year(From_unixtime (Blogcreatetime))= Year(Curdate ()) Second, query quarterly data query data with quarter numberSELECTArticleID, Quarter (from_unixtime (' Blogcreatetime ')
Mysql> SELECT something from Tbl_name
WHERE To_days (now ()) –to_days (date_col)
DayOfWeek (date)
Returns the week index of date (1 = Sunday, 2 = Monday, ...). 7 = Saturday). Index values are compliant with ODBC standards.
mysql> SELECT DayOfWeek ('
The following query selects the records for all date_col values within the last 30 days.
Mysql> SELECT something from Tbl_name
WHERE To_days (now ())-To_days (Date_col) DayOfWeek (date)
Returns the week index of date (1 = Sunday, 2 = Monday, ...). 7
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.