Q:

Write a PHP script to calculate the current age of a person

0

Write a PHP script to calculate the current age of a person.

Sample date of birth : 11.4.1987

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
$bday = new DateTime('11.4.1987'); // Your date of birth
$today = new Datetime(date('m.d.y'));
$diff = $today->diff($bday);
printf(' Your age : %d years, %d month, %d days', $diff->y, $diff->m, $diff->d);
printf("\n");
?>

Sample Output:

 Your age : 30 years, 3 month, 0 days

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now