How to get only time from created_at in laravel

Updated at 28-Sep-2021, By samar

How to get only time from created_at in laravel

In this session, we’ll try our hand at solving the "How to get only time from created_at in laravel" puzzle by using the computer language.

You can get only time from created_at attribute in laravel. You have to pass the time format ('H:i:s') to format method to get the time format.
  • Get time from created_at attribute in laravel

    $model->created_at->format('H:i:s');
    

    Demo code

    Route::get('/get-time', function(){
        $user = App\Models\User::find(1);
        echo $user->created_at->format('H:i:s');
    });
    

    Output :

    00:38:40

    This code snippet will return the time of created_at attribute of user with id 1.

Back to code snippet queries related laravel