date format for date in laravel code example
Example 1: laravel datatable format date column
$projects = Project::select('id', 'name', 'date_start', 'date_end');
return Datatables::of($projects)
->editColumn('date_start', function ($request) {
return $request->date_start->format('Y-m-d');
})
->editColumn('date_end', function ($request) {
return $request->date_end->format('Y-m-d');
})
->filterColumn('date_start', function ($query, $keyword) {
$query->whereRaw("DATE_FORMAT(date_start,'%Y-%m-%d') like ?", ["%$keyword%"]);
})
->filterColumn('date_end', function ($query, $keyword) {
$query->whereRaw("DATE_FORMAT(date_end,'%Y-%m-%d') like ?", ["%$keyword%"]);
})
->make(true);
Example 2: format time laravel
{{\Carbon\Carbon::createFromFormat('H:i:s',$time)->format('h:i')}}
{{$item->date_seance->format('d/m/Y') }}
{{date('H:i', strtotime($item->start_time)) }}