ItSolutionStuff.com

How to Calculate Age from Date of Birth in PHP?

By Hardik Savani • May 14, 2024
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...

Tags: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

šŸ“ŗ Subscribe on YouTube

We Are Recommending You

ā˜…

How to Check If Date is Past Date in PHP?

Read Now →
ā˜…

How to Get Month Name from Date in PHP?

Read Now →
ā˜…

How to Get Full Day Name from Date in PHP?

Read Now →
ā˜…

How to Get Previous Month from Date in PHP?

Read Now →
ā˜…

How to Get Next Month Date in PHP?

Read Now →
ā˜…

How to Get Tomorrow Date in PHP?

Read Now →
ā˜…

How to Get Yesterday Date in PHP?

Read Now →
ā˜…

PHP Subtract Seconds from Time Example

Read Now →
ā˜…

How to Subtract Minutes from DateTime in PHP?

Read Now →
ā˜…

How to Subtract Hours from DateTime in PHP?

Read Now →