-1

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'));
  • Wherever you print the time and date, just format to fit your needs. Example: `\Carbon\Carbon::parse($data->calldate)->format('d.m.Y')`. Or actually I might misunderstand your question. – Laralex Oct 24 '22 at 06:47
  • Perhaps `'DATE(calldate) as ibdate'` instead of `'calldate as ibdate'`? – KIKO Software Oct 24 '22 at 06:47
  • when i do as 'calldate as ibdate' i get error of undefined calldate column – ayesha maqsood Oct 24 '22 at 06:49
  • What have you tried so far? Where are you stuck? If this is really about printing (like given in the title of your question), please share more details. The currently shared code does not print anything – Nico Haase Oct 24 '22 at 07:36

2 Answers2

0

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 \Carbon\Carbon::parse($item->calldate)->format('d.m.Y');
}
Zain Farooq
  • 2,956
  • 3
  • 20
  • 42
0

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();
OMR
  • 11,736
  • 5
  • 20
  • 35