How to create the PHP Script to Calculate the Age Using the
Inputs Of our Birth date and the Current date?

Answer Posted / sindhu

<?
$year=$_POST['year'];
$mon=$_POST['mon'];
$dt=$_POST['dt'];
if ($_POST['submit']!="")
{

$a=date("d");
echo "this is cu date".$a."<br>";
$b=date("m");
echo "this is cu month".$b."<br>";
$c=date("Y");
echo "this is cu date".$c."<br>";

if ($b < $mon && $a > $dt )
{
$age=$c-$year-1;
$e=12-$mon;
$month=$b+$e;
$f=$a-$dt;
echo "You
are"."&nbsp;&nbsp;".$age."years"."&nbsp;&nbsp;&nbsp;".$month."Months"."&nbsp;&nbsp;".$f."Days"."&nbsp;&nbsp;"."old";
}
if ($b < $mon && $a < $dt )
{
$age=$c-$year-1;
$e=12-$mon-1;
$month=$b+$e;
$f=$dt-$a;
$g=30-$f;
echo
$age."years"."&nbsp;&nbsp;&nbsp;".$month."Months"."&nbsp;&nbsp;".$g."Days";
}
if ($b > $mon && $a > $dt)
{
$age=$c-$year;
$month=$b-$mon;
$f=$a-$dt;
echo
$age."years"."&nbsp;&nbsp;&nbsp;".$month."Months"."&nbsp;&nbsp;".$f."Days";
}
if ($b > $mon && $a < $dt)
{
$age=$c-$year;
$month=$b-$mon-1;
$f=$dt-$a;
$g=30-$f;
echo
$age."years"."&nbsp;&nbsp;&nbsp;".$month."Months"."&nbsp;&nbsp;".$g."Days";
}
if ($b == $mon && $a < $dt )
{
$age=$c-$year-1;
$month=11;
$f=$dt-$a;
$g=30-$f;
echo
$age."years"."&nbsp;&nbsp;&nbsp;".$month."Months"."&nbsp;&nbsp;".$g."Days";
}
if ($b == $mon && $a > $dt )
{
$age=$c-$year;
$month=0;
$f=$a-$dt;
echo
$age."years"."&nbsp;&nbsp;&nbsp;".$month."Months"."&nbsp;&nbsp;".$f."Days";
}
if ($b < $mon && $a == $dt )
{
$age=$c-$year-1;
$e=$mon-$b;
$month=12-$e;
$f=0;
echo
$age."years"."&nbsp;&nbsp;&nbsp;".$month."Months"."&nbsp;&nbsp;".$f."Days";
}
if ($b > $mon && $a == $dt )
{
$age=$c-$year;
$month=$b-$mon;
$f=0;
echo
$age."years"."&nbsp;&nbsp;&nbsp;".$month."Months"."&nbsp;&nbsp;".$f."Days";
}
if ($b == $mon && $a == $dt )
{
$age=$c-$year;
$month=0;
$f=0;
echo
$age."years"."&nbsp;&nbsp;&nbsp;".$month."Months"."&nbsp;&nbsp;".$f."Days";
}
}
?>

Is This Answer Correct ?    6 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which functions are used to count the total number of array elements in php?

530


Tell me what is the actually used php version?

550


Which function would you use to replace a record in a database in php?

579


Who is known as the father of php?

552


What is the difference between overloading and overriding in php?

531






Is it possible to protect special characters in a query string?

523


What is cookie and session in php?

499


How to execute a php script from the command line?

554


What are the different loops in php?

531


Tell us how can we access the data sent through the url with the post method?

517


What is the function in PHP do not return a timestamp?

561


What is different between software and app

1224


Tell me is it possible to remove the html tags from data?

522


What is php dependency injection?

520


How to store the uploaded file to the final location?

508