I have a problem, I want to recover dynamically what happened seven days ago, and then what happened six, five and so on until 1 day ago. The problem is that when I do between the date accumulates the data, it does not bring me what happened exactly 7 days if not that it brings me the accumulated of these 7 days.
for ($i=7; $i > 0; $i--)
{
$q = "select count(*) as cnt, 'promedio' as col
from oreData.events
where evt_listener <> $prop_id
and evt_date between now() - interval $i day and now()
union
select count(*) as cnt, evt_listener as col
from oreData.events
where evt_listener = $prop_id
and evt_date between now() - interval $i day and now()";
}
I tried to filter it with
and YEAR(evt_date) = YEAR(NOW())
and MONTH(evt_date) = MONTH(NOW())
and DAY(evt_date) = DAY(NOW() - INTERVAL $i DAY)
The problem is that if I am on day 1 of either month or the first day of the year the condition is no longer met, as I fix this
Thanks for the suggestions