What if you try this way?
Carbon\Carbon::createFromFormat('d-m-Y', '2019-05-15 20:38:42');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I wanna get only Y:M:D. In laravel the created_at returns Y,M,D, hour, minutes and second. I tried to use public function getFromDateAttribute($value) { return \Carbon\Carbon::parse($value)->format('d-m-Y'); } in the user model. It still returns 2019-05-15 20:38:42
created_at (and updated_at) should already be a carbon instance if working with an Eloquent Model. All you should have to do is format it.
Like in the view
{{ $user->created_at->format('d-m-Y') }}
Please or to participate in this conversation.