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

Question

I have already search for this, and i did find some topics discussing this problem, however none of which I felt like was the way I want to go, so therefore I hope to get a better sugestion here.

I want to get a timestamp from when a user was last updated.

$user->updated_at

If i run this, it gives 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 the timestamp.

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

How do i fetch the "date" from the carbon instance, so I only get 2017-01-04 00:35:38 - I have no idea where .000000 comes from, as this doesn't show up in the database. In the MySQL database, it simply shows 2016-07-20 20:23:07 as of type timestamp.

Hope for some pointers and suggestions


Show source
| php   | mysql   | laravel   | laravel-5.2   2017-01-04 02:01 1 Answers

Answers to Object of class Carbon\Carbon could not be converted to int ( 1 )

  1. 2017-01-04 02:01

    The Carbon object has a toDateTimeString method you can use:

    $user->updated_at->toDateTimeString();
    

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

Leave a reply to - Object of class Carbon\Carbon could not be converted to int

◀ Go back