title: How to convert Birth date to age ( years, months, days ) and age( years, months, days ) to birth date conversion in PHP?
body: <p>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 <strong>strtotime()</strong> 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 <strong>date_diff()</strong> function to retrieving the age (years, months, days). Any solution for my problem ?  </p>
  
  <pre class="lang-php prettyprint-override"><code>
  $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-&gt;y; // showing 2
  echo $diff-&gt;m; // showing 2
  echo $diff-&gt;d; // showing 22 (it should be 20)
  
  </code></pre>