Source Code:
(back to article)
<?php function calculateAge($dob) { $today = new DateTime(); $diff = $today->diff(new DateTime($dob)); return $diff->y; } $dob = '2000-01-01'; $age = calculateAge($dob); echo "Age is: $age";
Result:
Report an issue