How to get date from created_at field in laravel

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

Answers 1
  • 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