Created
May 19, 2021 10:33
-
-
Save mocfaisal/a7ecf8507719f3a9429dfd906c60d8e1 to your computer and use it in GitHub Desktop.
calculating age based on date of birth, resulting in year, month, day
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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