Ads
affiliate program
Pages
Home
About Kapil Kumar
Mysql
Sunday, 30 November 2014
Calculating age in years in php
Age calculation in php
Declare a function =>
function getAge( $dob, $date )
{
$dob=strtotime($dob);
$date=strtotime($date);
$age = 0;
while( $date > $dob = strtotime('+1 year', $dob))
{
++$age;
}
return $age." years";
}
Assign values to variables=>
$dob= "01-07-1991";
$today_date=date("d-m-Y");
Call the function =>
echo "Total age ". getAge($dob,$today_date);
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment