How to calculate Age from date of birth in PHP

The question is: How to calculate Age from date of birth in php

This Question asked in Interview

We are going to calculate age if we know the date of birth.

Here is the PHP Script:

<?php
$birthdate = new DateTime('1991-01-13');
$today   = new DateTime('today');
$age = $birthdate->diff($today)->y;
echo $age;
?>

OUTPUT:
24




No comments:

Post a Comment

We are here to listen you, Comment your valueable opinion...!!!