|
Added on 06.09.09 |
| Clicks 2102 |
| Rating: 5.00 out of 5 from 3 raters |

If you need to find the age of somebody with the date of birth,here is a simple function for that. .
We assume that all the functions will be saved in a file called php_functions.php
Explaining the above function is quite simple, as you can see ,it has
only 1 parameter
$date_of_birth is where you enter
the date of birth of the person.It must be in this format: d-mm-yyyy
or mm/d/yyyy
$dob =date('Y-m-d', strtotime($date_of_birth));This line of code gets the given date in the correct format
$age = date('Y') - date('Y', strtotime($dob));$age will hold the result of the difference between today's year and the year of DOB
if (date('md') < date('md', strtotime($dob))) {
$age--;
} if today's day is not your birthday yet, this line of code will subtract 1
year from your age.
See the example below to use the function
Try the example below