1 year ago

Call to a member function diff() on string

Posted 1 year ago by AKmahato

I want to calculate the difference between the current date and some date which is stored in my database. When I run my code I got this(Call to a member function diff() on a string) error. Can you please tell me how to resolve this error?

This is my code

$users = DB::table('customer_grievance_forms')->select('cg_id','created_at')->get();
        $count= count($users);
        foreach($users as $data){
            $fromData = $data->created_at;
           // print_r($fromData);

           echo "Previous Date Is :".$fromData;
           echo "</br>";

        $date = Carbon\Carbon::now()->toDateTimeString();
        echo "Current Dtae is :".$date;

        $difference = $date->diff($fromData);

        echo "Difference is :"+$difference;

Please sign in or create an account to participate in this conversation.