skip to Main Content

The following query is giving me time with date but i need only date .How do I do?

$data = DB::table('kahanighar_ivr.kahani_cdr')
                ->select(DB::raw('count(*) as a'),'dst','calldate as ibdate',DB::raw('"kahani" as ser'))
                ->where('dst','like','%7787%')
                ->wheredate('calldate','>=',"$request->start")
                ->wheredate('calldate','<=',"$request->end")
                ->groupBy('dst')->groupBy('calldate')
                ->union(DB::table('kids_ivr.kids_cdr')
                    ->select(DB::raw('count(*) as a'),'dst','calldate as ibdate',DB::raw('"kids" as ser'))
                    ->where('dst','like','%7787%')
                    ->wheredate('calldate','>=',"$request->start")
                    ->wheredate('calldate','<=',"$request->end")
                    ->groupBy('dst')->groupBy('calldate'))
                ->union(DB::table('news_ivr.news_cdr')
                    ->select(DB::raw('count(*) as a'),'dst','calldate as ibdate',DB::raw('"news" as ser'))
                    ->where('dst','like','%7787%')
                    ->wheredate('calldate','>=',"$request->start")
                    ->wheredate('calldate','<=',"$request->end")
                    ->groupBy('dst')->groupBy('calldate'));

2

Answers


  1. Put ->get() at the end of the query to get the data

     $data = DB::table('kahanighar_ivr.kahani_cdr')
                    ->select(DB::raw('count(*) as a'),'dst','calldate as ibdate',DB::raw('"kahani" as ser'))
                    ->where('dst','like','%7787%')
                    ->wheredate('calldate','>=',"$request->start")
                    ->wheredate('calldate','<=',"$request->end")
                    ->groupBy('dst')->groupBy('calldate')
                    ->union(DB::table('kids_ivr.kids_cdr')
                        ->select(DB::raw('count(*) as a'),'dst','calldate as ibdate',DB::raw('"kids" as ser'))
                        ->where('dst','like','%7787%')
                        ->wheredate('calldate','>=',"$request->start")
                        ->wheredate('calldate','<=',"$request->end")
                        ->groupBy('dst')->groupBy('calldate'))
                    ->union(DB::table('news_ivr.news_cdr')
                        ->select(DB::raw('count(*) as a'),'dst','calldate as ibdate',DB::raw('"news" as ser'))
                        ->where('dst','like','%7787%')
                        ->wheredate('calldate','>=',"$request->start")
                        ->wheredate('calldate','<=',"$request->end")
                        ->groupBy('dst')->groupBy('calldate'))->get();
    

    Then use foreach loop to iterate the data

    foreach($data as $item)
    {
        echo CarbonCarbon::parse($item->calldate)->format('d.m.Y');
    }
    
    Login or Signup to reply.
  2. you can use mysql DATE function, it Extract the date part

    $data = DB::table('kahanighar_ivr.kahani_cdr')
                    ->select(DB::raw('count(*) as a'),'dst',DB::raw('Date(calldate) as ibdate',DB::raw('"kahani" as ser'))
                    ->where('dst','like','%7787%')
                    ->wheredate('calldate','>=',"$request->start")
                    ->wheredate('calldate','<=',"$request->end")
                    ->groupBy('dst')->groupBy('calldate')
                    ->union(DB::table('kids_ivr.kids_cdr')
                        ->select(DB::raw('count(*) as a'),'dst','calldate as ibdate',DB::raw('"kids" as ser'))
                        ->where('dst','like','%7787%')
                        ->wheredate('calldate','>=',"$request->start")
                        ->wheredate('calldate','<=',"$request->end")
                        ->groupBy('dst')->groupBy('calldate'))
                    ->union(DB::table('news_ivr.news_cdr')
                        ->select(DB::raw('count(*) as a'),'dst','calldate as ibdate',DB::raw('"news" as ser'))
                        ->where('dst','like','%7787%')
                        ->wheredate('calldate','>=',"$request->start")
                        ->wheredate('calldate','<=',"$request->end")
                        ->groupBy('dst')->groupBy('calldate'))->get();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search