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