Hello Reader's,
Sometimes we require to calculate the age of user from the date of birth to current date during registration of a new user to check whether he/she is eligible or not to participate in any competitions. In that case, you need to calculate the user age from date of birth.
This quick tutorial will guide you about how to calculate age in PHP based on date of birth
and the current date. Here is short code snippet given below.
<?php
$DOB = "13-03-1990";
$today = date("Y-m-d");
$difference = date_diff(date_create($DOB), date_create($today));
echo 'Your age is '.$difference->format('%y');
?>
In the above code date(), date_create(), and date_diff() functions are used to calculate age of the user.
0 Comment(s)