Age calculator in PHP -

Age calculator in PHP


How to make age calculator in PHP

You are aprox 26 years and 4 months old
choose your DOB

Create an age Calculator(Enter your DOB in text box)


Age Calculator

Your Age is: 26 years 4 months 0 days
enter current date:
enter your DOB:

In the above example
Create a HTML script to take input from users separated by “/” current(year, month, date) and his date of birth (year, month, date).
Convert the inputted value mm/dd/yyyy string into array using explode( ) function for both current date and date of birth.
strore these values in $arr variable at 0 index date, at 1 index month and at 2 index year like
same as for (date of birth) inside $brr variable.
Now check for date if current “date” is less than date of birth “date” then borrow 1 month and add 30days in current date and calculate.
Same as for Month here borrow 1year from existing year and add 12 months.
subtract current months with date of birth “month” and store in $mon variable.
at last calculate for year and store the value in $yr variable.
Display the all calculated values(Year,Month, Date) like: 26 years 4 months 0 days