I have the following code I want to return the date found in my database mysql
in datetime format. How do I convert it to date and format it from a select
query builder with laravel
?.
public function fecha(){
$fechas= DB::table('detail_books')->select('DATE_FORMAT('fechallegada','%d-%m-%Y')')->get();
return view("factura",compact('fechas'));
}
However I get an error in the select.
Cheers
syntax error
Try this:
Using the combination of single quotes in the following statement is generating the error.
You should try replacing with:
Update
You must use
selectRaw
to format from the query. The code should be as follows: