I have a form where the user can input a patient age in years, months and days. That will save the data in the database according to the patient's date of birth. The problem is I'm using strtotime() function to get the DOB of the patient, but when I want to show the age (years, months, days) from retrieving the date form the birthday column, sometimes it showing 1 or 2 days (+-) result. I'm using date_diff() function to retrieving the age (years, months, days). Any solution for my problem ?
$today = date("Y-m-d");
$dateOfBirth = strtotime("$today -2 years -2 months -20 days");
$birthday = date("Y-m-d", $dateOfBirth);
//and then tried to retrieve the age from that date which give me wrong answer
$diff = date_diff(date_create($birthday), date_create($today));
echo $diff->y; // showing 2
echo $diff->m; // showing 2
echo $diff->d; // showing 22 (it should be 20)