php - Display results from past days

223

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.

46

Answer

Solution:

Try this..

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

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

Answer

Solution:

You can also try this :

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'");

People are also looking for solutions to the problem: php - Days Until Date

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.