Ad

Convert Time Using Mysql Laravel 5

- 1 answer

i want to view the time which store on DB 12:00:00 as 12:00 PM.

here is my code

$late_running = Late_runnings::select(DATE_FORMAT('late_time','%h:%i %p'))
                    ->where('user_id', '=', $driver_id->id)
                    ->where('role_id', '=', 1)
                    ->get();

im getting follwing error

date_format() expects parameter 1 to be DateTimeInterface, string given

pls advice

Ad

Answer

DATE_FORMAT is a mysql property so you need to select it as a raw sql like,

Late_runnings::selectRaw("DATE_FORMAT('late_time','%h:%i %p')")...

didn't test it give it a try. :)

Ad
source: stackoverflow.com
Ad