how to calculate number of Age from date of birth in PHP?

I am explaining you, how to calculate number of Age from date of birth in PHP. if you want to show user’s age from date of birth so you can use this process and show Age in php. here I will use some function like date(), date_create() and date_diff() that need to used to calculate the age from date of birth in PHP. it is simple process.

Example :

<?php
  $UsersdateOfBirth = "20-10-2001";
  $currentDate = date("Y-m-d");//like 18-12-2022
  $Calculatediff = date_diff(date_create($UsersdateOfBirth), date_create($currentDate));
  echo 'Here, User age is '.$Calculatediff->format('%y');
?>

Output :

Here, User age is 21

Leave a Reply

Your email address will not be published. Required fields are marked *

57 − = 50