This guide covers calculate age from date of birth PHP with practical steps you can copy into a real project.

Calculate age from date of birth PHP

In one of my projects, we needed to calculate a user’s age from their date of birth.

It is very easy to calculate age from date of birth. For more details, check out the following snippet:

# object oriented
$from = new DateTime('1992-01-04');
$to   = new DateTime('today');
echo $from->diff($to)->y;

echo "</br>";
echo date_diff(date_create('1992-01-04'), date_create('today'))->y;

Reference: Stack Overflow. You can also download the code from here.

Thanks for reading, and let me know if you need any changes.

Related reading

Questions? Use the contact page.

Reference: PHP DateTime docs.