Skip to content

Instantly share code, notes, and snippets.

@mocfaisal
Created May 19, 2021 10:33
Show Gist options
  • Save mocfaisal/a7ecf8507719f3a9429dfd906c60d8e1 to your computer and use it in GitHub Desktop.
Save mocfaisal/a7ecf8507719f3a9429dfd906c60d8e1 to your computer and use it in GitHub Desktop.
calculating age based on date of birth, resulting in year, month, day
<?php
// refference : https://www.w3resource.com/php-exercises/php-date-exercise-18.php
$bday = new DateTime('2021-05-18'); // Your date of birth
$today = new Datetime(date('Y-m-d'));
$diff = $today->diff($bday);
printf(' Your age : %d years, %d month, %d days', $diff->y, $diff->m, $diff->d);
printf("<br>");
printf("<br>");
echo "Years : " . $diff->y;
printf("<br>");
echo "Month : " . $diff->m;
printf("<br>");
echo "Days : " . $diff->d;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment