Welcome back to shortlearner.com , today in this post we will see how to find the age of the user on the basis of their date of birth.
so we are going to write a program in php that will help us to calculate age.
<?php //date in mm/dd/yyyy format; or it can be in other formats as well $birthDate = "12/17/1983"; //explode the date to get month, day and year $birthDate = explode("/", $birthDate); //get age from date or birthdate $age = (date("md", date("U", mktime(0, 0, 0, $birthDate, $birthDate, $birthDate))) > date("md") ? ((date("Y") - $birthDate) - 1) : (date("Y") - $birthDate)); echo "Age is:" . $age; ?>
in the below program we are declared a variable $birthDate with having a date in mm/dd/yyyy format. after that we are using predefined php function explode(), so with the help of that function we will explode the date to get month ,date and year as well. after that we will calculate the age of user on the basis of user’s date of birth and current date.
How to Install PHP on CentOS.
How to Send Attachment on mail using PHP.
PHP Login Script With Remember me.
Unable to create a directory a wordpress error
How to integrate Razorpay Payment Gateway using PHP.