Aaron
Aaron

Reputation: 4480

Using diffForHumans with strototime

I am trying to use diffForHumans with a date that is in string format. I used strtotime to convert the string to Unix Timestamp. The problem is now I am getting an error that cannot covert integer to time. What am I missing?

Here is my code.

<td>{{strtotime($user['scan'])->diffForHumans(time())}}</td>

$user['scan'] is a date that is a string

Upvotes: 1

Views: 255

Answers (1)

Sandeesh
Sandeesh

Reputation: 11906

Use parse. The date is compared to the current time by default.

<td>{{ \Carbon\Carbon::parse($user['scan'])->diffForHumans() }}</td>

Upvotes: 3

Related Questions