Search code examples
laravelphp-carbonlaravel-5.6

Carbon diffForHumans cant use in laravel 5.5?


first I use Carbon\Carbon; then I try to echo difforhumans reference by doc : https://carbon.nesbot.com/docs/#api-humandiff

echo Carbon::parse('2019-08-03')->diffForHumans('2019-08-13');

laravel 5.5 said Parse error: syntax error,

UPDATE

I install laravel 5.6 but I downgrade into 5.5

here is my full code

use Carbon\Carbon;
    public function index(Request $request)
    {
        dd(\Carbon\Carbon::parse('2019-08-03')->diffForHumans('2019-08-13'));

    }

enter image description here


Solution

  • First of all diffForHumans don't take any arguments.If just removing the date from diffForHumans won't work..

    Try this:

    use Carbon\Carbon;
        public function index(Request $request)
        {
            dd(Carbon::createFromFormat('Y-m-d','2019-08-03')->diffForHumans());
    
        }