Home > Enterprise >  How to print date without time in laravel?
How to print date without time in laravel?

Time:10-24

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','w87%')
                ->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','w87%')
                    ->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','w87%')
                    ->wheredate('calldate','>=',"$request->start")
                    ->wheredate('calldate','<=',"$request->end")
                    ->groupBy('dst')->groupBy('calldate'));

CodePudding user response:

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','w87%')
                ->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','w87%')
                    ->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','w87%')
                    ->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');
}

CodePudding user response:

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','w87%')
                ->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','w87%')
                    ->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','w87%')
                    ->wheredate('calldate','>=',"$request->start")
                    ->wheredate('calldate','<=',"$request->end")
                    ->groupBy('dst')->groupBy('calldate'))->get();
  • Related