我尝试使用php和mysql获取最近7天的记录。我将结果保存在数据库dd-mm-yyyy格式中。
$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'"));
从这段代码中我得到了过去7天的记录,但有些时候它没有给出准确的结果。
答案 0 :(得分:0)
试试这个..
$date = date('Y-m-d',time()-(7*86400));
$sql = "SELECT * FROM registration_form WHERE appointment_date <='$date' ";
答案 1 :(得分:0)
你也可以试试这个:
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'");