PHP Query the last 30 days, 7 days, daily, yesterday, last month's records PHP multi-table query PHP query system PHP multi-conditional check

Source: Internet
Author: User
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.

  • Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.