phplaravellaravel-5laravel-5.3php-carbon

How to parse datetime using Laravel on date and time?


I have datetime string: 2016-11-01 15:04:19

How I can get date and time separated?


Solution

  • You can do

     $model->created_at->format('Y-m-d');
    

    to format a specific date. This solution will only work if your date is a Carbon instance. Or you can use Mutators to format a date by default and make it a Carbon instance if necessary.https://laravel.com/docs/5.3/eloquent-mutators#date-mutators