Query data for 7 days ahead:
[HTML]View PlainCopyprint?
- SELECT * from data table where Date_sub (Curdate (), INTERVAL 7 day) <= the Time field name you want to judge
[HTML]View PlainCopy print?
Query data for 30 days ahead:
[HTML]View PlainCopyprint?
- SELECT * from data table where Date_sub (Curdate (), INTERVAL Day) <= The time field name you want to judge
[HTML]View PlainCopy print?
To query data between a certain date:
[HTML]View PlainCopyprint?
- SELECT * from data table where time field name between ' 2016-02-01 ' and ' 2016-02-05 '
Query data for 3 months ahead:
[HTML]View PlainCopy print?
- SELECT * from data table where time field name between Date_sub (now (), INTERVAL 3 MONTH) and now ()
[HTML]View PlainCopyprint?
Query data for one year ahead:
[HTML]View PlainCopyprint?
- SELECT * from data table where time field name between Date_sub (now (), INTERVAL 1 years) and now ()
[HTML]View PlainCopyprint?
Query this month's data
[HTML]View PlainCopyprint?
- SELECT * from data table where Date_format (Time field name, '%y-%m ') =date_format (now (), '%y-%m ')
Query last month's data
SELECT * from data table where Date_format (Time field name, '%y-%m ') =date_format (Date_sub (Curdate (), INTERVAL 1 MONTH), '%y-%m ')
Query this week's data
[HTML]View PlainCopyprint?
- SELECT * from data table where Yearweek (date_format (Time field name, '%y-%m-%d ')) = Yearweek (now ())
Query data for last week
[HTML]View PlainCopyprint?
- SELECT * from data table where Yearweek (Date_format (create_time, '%y-%m-%d ')) = Yearweek (now ())-1
I hope you find the blog has errors and I proposed that bloggers will be the first time to update the article.
Thank you.
MySQL SQL statement for querying data by date