Extract only time from datetime in laravel

Updated at 24-Sep-2021, By samar

Extract only time from datetime in laravel

In this tutorial, we will try to find the solution to "Extract only time from datetime in laravel" through programming.

Sometimes you have to get only time from datetime column value. You can extract only time from datetime value from specific column in Laravel
  • Get time from created_at attribute in laravel

    Syntax

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

    Demo code

    routes\web.php

    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