Hi! It the table Stewards I have 'dob' column where are stored birthdays dates. I would like to calculate age from birthday. I tried to use in Steward model:
public function age() {
return $this->dob->diffInYears(\Carbon::now());
}
, but I have no idea what to write in Resource file. Any help?
I faced another problem with age: the birthday is e.g. 20-02.2018. I would like all 2020 year how age of this person as 2 years old. Count diff between years, not diff between dates. Right now the age shows as 1 year old. Is there any method to make it?
My current code:
public function getAge()
{
return $this->dob->diff(Carbon::now())
->format('%y years, %m months and %d days');
}
Yes, exacly. I need all year to have the same age. If someone was born on 01-01 or 31.12, all year I have to show as the same age. So, basically the age must be counted only based on the year, not month and day.