An object of class Carbon \ Carbon cannot be converted to int

I was already looking for this, and I found several topics discussing this issue, however, none of which I felt was the way I want to go, so I hope to get a better offer here.

I want to get the timestamp since the last update of the user.

$user->updated_at 

If I ran this, he gave me this error

 Object of class Carbon\Carbon could not be converted to int 

This is because it returns a Carbon instance in Laravel 5.2, and I only need a timestamp.

 Carbon {#303 โ–ผ +"date": "2017-01-04 00:35:38.000000" +"timezone_type": 3 +"timezone": "UTC" } 

How to get the โ€œdateโ€ from a carbon instance, so I only get 2017-01-04 00:35:38 - I have no idea where .000000 comes from, because it does not appear in the database. In the MySQL database, it just shows 2016-07-20 20:23:07 as a timestamp .

I hope for some recommendations and suggestions

+5
source share
1 answer

The Carbon object has a toDateTimeString method, which you can use:

 $user->updated_at->toDateTimeString(); 

It will give you the value 2017-01-04 00:35:38 as a string.

+7
source

Source: https://habr.com/ru/post/1262251/


All Articles