I am building a chart and for that extracting data from the past 24 hours, 48 hours, 1 week and 2 weeks.
I used INTERVAL statements for this purpose but they are not working as expected. I am using Laravel. Here is the function to extract the data:
public function range($range)
{
$data = new Main();
$data0 = $data->whereRaw('updated_at >= DATE_SUB(NOW(), INTERVAL '.$range.')')->whereRaw('MINUTE(updated_at)>54')->orwhereRaw('MINUTE(updated_at)<6')->where('server_short_name', '=', 'FiveRP')->get();
$data1 = $data->whereRaw('updated_at >= DATE_SUB(NOW(), INTERVAL '.$range.')')->whereRaw('MINUTE(updated_at)>54')->orwhereRaw('MINUTE(updated_at)<6')->where('server_short_name', '=', 'GTALife')->get();
$data2 = $data->whereRaw('updated_at >= DATE_SUB(NOW(), INTERVAL '.$range.')')->whereRaw('MINUTE(updated_at)>54')->orwhereRaw('MINUTE(updated_at)<6')->where('server_short_name', '=', 'GermanV')->get();
return compact('data0', 'data1', 'data2');
}
Here is the function that calls the view:
public function hours24()
{
$t = $this::range('24 HOUR');
return view('chart', $t);
}
But in the chart, I am getting results from 22nd of May as well which is the earliest date on DB. Which means that the code isnt working as expected although it is correct according to me. Is there something I am missing out?