Tuesday, January 25, 2022

[FIXED] Display Error when format date in Laravel

Issue

I am beginner in Laravel.

I have date:

Illuminate\Support\Carbon @1577636272 {#912 ▼
  date: 2019-12-29 17:17:52.0 Europe/Warsaw (+01:00)
}
$userLastActivity = $userLastActivity->format('Y-m-d H:i');

When I try convert it I have error:

Call to a member function format() on null

How can I repair it?


Solution

I assume $userLastActivity is a date or carbon instance. you can use Carbon::parse for date parse.

\Carbon\Carbon::parse($userLastActivity)->format('Y-m-d H:i');


Answered By - Dilip Hirapara

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.