How to parse datetime using Laravel on date and time?

Carbon comes with multiple setters and getters.

http://carbon.nesbot.com/docs/#api-getters

If you have a datetime string and you want to use it with a Carbon instance you can do:

$date = \Carbon\Carbon::parse('2016-11-01 15:04:19');

Then you can do something like:

$date->format('Y-m-d')
$date->format('H:i:s')

That being said, if you are getting this datetime from an Eloquent model then you should look at @AlexeyMezenin or @Christophvh answer.

Hope this helps!


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


if you try these,

$stringTime = '2016-11-01 15:04:19';

return date('Y-m-d', strtotime($stringTime));

return date('H:i:s', strtotime($stringTime));

And carbon also avail,

Carbon::parse();

Carbon

php date

It is okay for you..

I hope it will help you.