Hello
Below is the code by which I trying to get AGE of students as on 31-March of current year in this format -> 6 years, 3 months, 14 days. But I am getting differnece in Days. I checked the age from this site http://www.calculator.net/age-calculator.html
Example 1. 19-12-2007 should display 6 years 3 months 12 days
Where as my code displaying - 6 Years , 3 Months , 13 Days
Example 2. 29-06-2009 should display 4 years 9 months 2 days
Where as my code displaying - 4 Years , 9 Months , 6 Days
Here is the code -
<?php
function dt_wrd($date)
{
$date1 = $date;
$date2 = "31-03-".date('Y');
$diff = abs(strtotime($date2) - strtotime($date1));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
$ys="s";
$ms="s";
$ds="s";
if($months=="1" ||$months=="0" )
{
$ms="";
}
if($years=="1" ||$years=="0" )
{
$ys="";
}
if($days=="1" ||$days=="0" )
{
$ds="";
}
echo "$years Year$ys , $months Month$ms , $days Day$ds";
}
$date1='29-06-2009';//$_GET['dob'];
dt_wrd($date1);
?>