简体   繁体   中英

Display results from past days

I try to get last 7 days records using php and mysql. I am saving the results in database dd-mm-yyyy format.

$start = date('d-m-Y',strtotime('-7 days'));
$end = date('d-m-Y',strtotime('now'));

mysqli_query($link, "SELECT count(*) FROM `registration_form` WHERE `appointment_date` BETWEEN '$start' and '$end' and `registration_type` = 'provisional_registration'"));

from this code i get the records from last 7 days but some time its not give accurate results.

Try this..

$date = date('Y-m-d',time()-(7*86400)); 

$sql = "SELECT * FROM registration_form WHERE appointment_date <='$date' ";

您也可以尝试以下方法:

mysqli_query($link, "SELECT count(*) FROM `registration_form` WHERE `appointment_date` BETWEEN NOW() and DATE_SUB(NOW(), INTERVAL 7 DAY) and `registration_type` = 'provisional_registration'");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM