Question

I am developing an PHP and mySQL based Blood Donating application. I want to show those blood donor who are didn't donate blood in last three month from today's date.How can I write the query for show those data..?

No correct solution

OTHER TIPS

You can do this with strtotime

$date1 = date("Y-m-d");
$date2 = date("Y-m-d",strtotime("-3 month"));

Then put this dates into BETWEEN Sql statement like;

WHERE date BETWEEN '.$date1.' AND '.$date2.'

you can add query below

SELECT date FROM table WHERE date BETWEEN CURDATE() - INTERVAL 3 MONTH AND CURDATE()

OR you can use the below condition with your query.

SELECT DATE_SUB(NOW(), INTERVAL 3 MONTH;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top