Solving a php problem is a matter of time comparison.

Source: Internet
Author: User
Solving a php problem is that a time comparison problem always results in zero data. do you need to convert the data format? the database time is year: Month: day hour minute second. do you need to convert it to year, month, or day, the key is how to switch. what is the loss ;? Phpfor ($ i0; $ I & lt; 30; $ I ++) {$ tomorrowmktime (0, 0, 0, date (& quot; m & quot ;), date (solving a php problem is a time comparison problem
The output data is always 0. do you need to convert the data format? the database time is year: Month: day, hour, minute, and second. do you need to convert it to year, month, and day? the key is how to convert it.
For ($ I = 0; $ I <30; $ I ++ ){
$ Tomorrow = mktime (0, 0, 0, date ("m"), date ("d")-$ I, date ("Y "));
$ SQL = "select count (*) from customers_info where customers_info_date_account_created = '". date ("Y-m-d", $ tomorrow )."'";
$ Result = mysql_query ($ SQL, $ conn) or
Die ("Error:". mysql_error );
$ Row = mysql_fetch_row ($ result );
Echo $ row [0]."
";
}
?>



------ Solution --------------------
$ SQL = "select count (*) from amp_test where date '". date ("Y-m-d", ($ tomorrow-3600*24 )). "'and '". date ("Y-m-d", $ tomorrow ). "'";
Output:
1257292800 select count (*) from amp_test where date between '2017-11-03 'and '2017-11-04' 2
1257206400 select count (*) from amp_test where date between '2017-11-02 'and '2017-11-03' 1
1257120000 select count (*) from amp_test where date between '2017-11-01 'and '2017-11-02' 0
The format in the database I tested is timestamp, 11:13:25.
------ Solution --------------------
You can use DATE_FORMAT (your_field, '% Y-% m-% d') =... to convert

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.