lundi 29 avril 2019

access data from database to compare with current date to calculate total days

I have tried to access date stored in my db table and compare it with current date so that i can get the number of days but it shows this error

DateTime::__construct(): Failed to parse time string ([{"quit_date":null},{"quit_date":null}]) at position 0 ([): Unexpected character

This is the code that use in my controller

        $quit_date = Information::select('quit_date')
                ->where('user_id','=',\Auth::user()->id)
                ->get();
        $date = new Carbon($quit_date);
        $now = Carbon::now();
        $day = $date->diffInDays($now);

but if I set the $quit_date manually with the date for example "2019-04-25 00:00:00.000000", the code works fine and show the day different between the date, but when I use the Information::select to read the date from database, it shows error.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire