pakilala said:
Sir,
My date of Birth is 03-Sept-1987
and i want to compare it with current date i.e 08-April-2009.
and output should be the my current age. like 22 Yeas 08 Months 25 Days
plz help in my problem.
this is a simple solution:
PHP Code:
<?php
//your birthdate (YYYY-MM-DD)
$dateofbirth = strtotime("1987-09-03"); //converting to timestamp
//currect date (timestamp)
$today = time();
//difference
$diff = $today - $dateofbirth;
print "Your age in days:".floor($diff/86400) . "<br>";
print "Your age in hours:".floor($diff/3600) . "<br>";
print "Your age in minutes:".floor($diff/60) . "<br>";
//getting year timestamp (60*60*24*365) = 31536000 = one year
$years = floor($diff / 31536000);
$diff -= 31536000 * floor($diff / 31536000);
//getting months (60*60*24*365/12) = 2678400 = one month)
$months =floor($diff / 2678400);
$diff -= 2678400 * floor($diff / 2678400);
// days (60 * 60 * 24 = 86400) = one day
$days = floor($diff / 86400);
print "Age: ". $years . " years " . $months ." months ".$days ." days";
?>
Output:
Your age in days:7890
Your age in hours:189375
Your age in minutes:11362516
Age: 21 years 7 months 8 days
Bookmarks