How to get date from created_at field in laravel

Created at 01-Sep-2021 , By samar

How to get date from created_at field in laravel

We’ll attempt to use programming in this lesson to solve the "How to get date from created_at field in laravel" puzzle.

You can get date from created_at filed in laravel using toDateString() and format() method on created_at attribute.
  • Get date from created_at in laravel

    //toDateString() method
    $date = User::find(1)->created_at->toDateString();
    echo $date;
    //format() method
    $date = User::find(1)->created_at->format('Y-m-d');
    echo $date;
    //Output :

    You can change the default timestamp value of created_at attribute to in date format in laravel. This code snippet will get the record of user with id 1 and get the date from created_at attribute.

Back to code snippet queries related laravel

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.