Why can’t I recover the amount of record that corresponds to the date range?

Asked

Viewed 45 times

1

        $quantidade_week = DB::table('serviceorders')
        ->where('serviceorders.status_serviceorders', '=', 'OPENED')
        ->WhereDate('serviceorders.date_started_serviceorders', '>=', $firstDayOfInterval)
        ->WhereDate('serviceorders.date_started_serviceorders', '<=', $lastDayOfInterval)
        ->get()
        ->count();
        dd($quantidade_week);

inserir a descrição da imagem aqui

1 answer

2


The problem is what you’re doing ->get()->count();, to count it is not necessary to call the function get only the count:

$quantidade_week = DB::table('serviceorders')
    ->where('serviceorders.status_serviceorders', '=', 'OPENED')
    ->whereDate('serviceorders.date_started_serviceorders', '>=', $firstDayOfInterval)
    ->whereDate('serviceorders.date_started_serviceorders', '<=', $lastDayOfInterval)
    ->count();

dd($quantidade_week);
  • So @Guilherme Constamilam, I removed ->get, one more function to complicate the process, however, still persists resulting 0 records.

  • would not be because the date_started_serviceorders field is in format 2019-03-14 00:00:00 and the filter variable is 03/14/2019 ?

  • It’s very likely. Try passing in the same format, something like ->whereDate('serviceorders.date_started_serviceorders', '>=', date_create_from_format('d/m/Y', $firstDayOfInterval)). An important observation, the correct one is whereDate and not WhereDate

  • WOW! Thanks @Uilherme Costamilam Solved!!!!! I applied both tips and it worked perfect!

  • If the answer solved your problem mark it as accepted in the top left "v" button of the same

Browser other questions tagged

You are not signed in. Login or sign up in order to post.