How To Calculate Age From Date Of Birth In PHP?

How-To-Calculate-Age-From-Date-Of-Birth-In-PHP.jpg

Hiii Guys,

Now, let's see tutorial of how to calculate age from date of birth in php. step by step explain calculate date of birth from age in php. I’m going to show you about php age calculation from date of birth. you'll learn php calculate age from date of birth to today.

I will give you very simple example how to calculate age from date of birth in PHP. so let's see both examples with output:

Example 1: index.php
<?php

$dob='1994-07-01';
$year = (date('Y') - date('Y',strtotime($dob)));

echo $year;

?>
Output:
	27
Example 2: index.php
<?php

$dob = new DateTime('1994-07-01');
$today   = new DateTime('today');

$year = $dob->diff($today)->y;

echo $year;

?>
Output:
	27

I hope it can help you...