How to Calculate Age from Date of Birth in PHP?
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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Check If Date is Past Date in PHP?
- How to Get Month Name from Date in PHP?
- How to Get Full Day Name from Date in PHP?
- How to Get Previous Month from Date in PHP?
- How to Get Next Month Date in PHP?
- How to Get Tomorrow Date in PHP?
- How to Get Yesterday Date in PHP?
- PHP Subtract Seconds from Time Example
- How to Subtract Minutes from DateTime in PHP?
- How to Subtract Hours from DateTime in PHP?