jeudi 8 décembre 2016

Accessing data from date of birth to get the age

Sample Database
Id          scholar_birthday
1           2001-12-05
2           2002-10-15
3           1991-12-19
4           1990-02-25

$input  = Scholar::select('scholar_birthday')->get(); 
$strFromArr = serialize($input);
$format = 'Y/m/d';
$year = 'Y';
$month = 'm';
$day = 'd';
dd($format);
$date = Carbon::createFromFormat($year,$month,$day, $strFromArr);
dd($date);

Having problem with my code in getting the data from database column scholar_birthday.What i want here is to get the year,month,day individually so that i can put it in the parameter inside createFromFormat. But the result is:

<!-- the result of dd -->

A four digit year could not be found

Anyone have an idea on how to implement this in the right way?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire