How does mysql count the previous day's records? The time storage mode is: time ()

Source: Internet
Author: User
How does mysql count the previous day's records? The time storage mode is: CREATETABLE 'bean' ('usedate' varchar (12) defaultNULL of time (). the date field of the bean database for statistics is: usedate, which is written as select * frombeanwheredate (usedate) = How Does dat mysql count the previous day's records? The time storage mode is: time ()
Create table 'bean '(
'Usedate' varchar (12) default NULL,


The date field of the bean database is usedate.

Write as follows:
Select * from bean where date (usedate) = date_sub (curdate (), interval 1 day );

But the error message is:
Warning: mysql_num_rows (): supplied argument is not a valid MySQL result resource in


Maybe the above mysql statement can only count the time in the format Y-m-d hh: mm. if the time is stored as time () such as 1340508737, can I count the records of the previous day ?!
Thank you!


This cannot be done either:
Select * from bean where to_char (usedate, 'yyyy-mm-DD') = date_sub (curdate (), interval 1 day );


------ Solution --------------------
SQL code
SELECT * FROM 'Bean' WHERE FROM_UNIXTIME ('usedate', '% Y-% m-% d') = DATE_SUB (CURDATE (), INTERVAL 1 DAY)

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.