Data-id= "1190000005009280" data-license= "CC" >
Some variable description: Add_time is the insertion time to_days is an SQL function that returns the number of days data_sub (Date,interval expr type) to the specified date minus how many days the data () function returns the date part of the date or date/time expression. The Curdate () function returns the current date Y-m-ddata_format used to display the date/time data in a different format Period_diff (P1,P2) returns the number of months between P1 and P2. The P1 and P2 formats are yymm or YYYYMM. Note that the period parameters P1 and P2 are not date values 1, query all records for today: (1) The Add_time field, which is the type of the INT (5) SELECT * from ' article ' where To_days (Date_format ( From_unixtime (' Add_time '), '%y-%m-%d ') = To_days (now ()); (2) The Add_time field is a datetime type or a timestamp type of select * from ' article ' where to_days (' add_time ') = To_days (now ())); 2, query all yesterday Record SELECT * from ' article ' where To_days (now ()) <= 1 + to_days (' Add_time '); 3. Information record for nearly 7 days: SELECT * from ' article ' WH Ere date_sub (Curdate (), INTERVAL 7 day) <= date (' Add_time '), 4, nearly 30 days of information recording: SELECT * from ' article ' where date_sub (curd Ate (), INTERVAL Day) <= date (' Add_time '); 5, query this month's record select * from ' article ' where Date_format (' add_time ', '%y%m ') = Date_format (Curdate (), '%y%m '); 6, last one month record select * from ' article ' where Period_diff (Date_format (now (), '%y%m '), Date_format (' add_time ', '%y%m ')) = 1;
The above describes the PHP query the last 30 days, 7 days, every day, yesterday, last month's records, including PHP, query content, I hope the PHP tutorial interested in a friend helpful.