How does MySQL count the day before the record? The time storage mode is:

Source: Internet
Author: User
How does MySQL count the previous day records? The time storage mode is:
CREATE TABLE ' Bean ' (
' usedate ' varchar () default NULL,


Statistics Bean Database Date field: Usedate

Write this:
SELECT * from beans where date (usedate) = Date_sub (Curdate (), Interval 1 day);

But there is an error, prompting:
Warning:mysql_num_rows (): supplied argument is not a valid MySQL result resource in


Perhaps the above MySQL statement can only be counted out y-m-d hh:mm such storage format of time, if the time is stored as 1340508737, please ask if the statistics of the previous day's record?!
Thank you!


It's not possible to change this:
SELECT * from Beans where to_char (usedate, ' yyyy-mm-dd ') = Date_sub (Curdate (), Interval 1 day);


------Solution--------------------
SQL Code
SELECT * from ' Beans ' WHERE from_unixtime (' usedate ', '%y-%m-%d ') = Date_sub (Curdate (), INTERVAL 1 day)
  • Related Article

    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.