3

I'm trying to get logs from the last 24 hours for a chart I'm building. I'm using Laravel 5.8.

I need 1 line per every 15 minutes for the chart to be accurate.

The current state is one line per hour, I can't think of out to turn it into 15 minutes.

Please help me to make it work and make the code look as pretty as possible!

public function getDataDay(&$data) {
    $data = $data->where('created_at', '>', Carbon::now()->subHours(23)->format('Y-m-d H:i:s'))
                  ->select('id', 'part_id', 'data', 'created_at')
                  ->selectRaw('HOUR(created_at) as hour')
                  ->groupBy('hour')
                  ->get();
}
Mat
  • 202,337
  • 40
  • 393
  • 406
CTOKoder
  • 33
  • 3
  • 1
    Possible duplicate of [How to group time by hour or by 10 minutes](https://stackoverflow.com/questions/5002661/how-to-group-time-by-hour-or-by-10-minutes) – Namoshek Oct 06 '19 at 11:53

1 Answers1

0

use this, it is what i use in mysql

->selectRaw('FROM_UNIXTIME(FLOOR( UNIX_TIMESTAMP(created_at)/900 ) * 900) AS quaterhour')
->groupBy('quaterhour')

Of Course if you have mire than one day, you have to group also by years , month and days

nbk
  • 45,398
  • 8
  • 30
  • 47