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"." ".$age."years"." ".$month."Months"." ".$f."Days"." "."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"." ".$month."Months"." ".$g."Days";
}
if ($b > $mon && $a > $dt)
{
$age=$c-$year;
$month=$b-$mon;
$f=$a-$dt;
echo
$age."years"." ".$month."Months"." ".$f."Days";
}
if ($b > $mon && $a < $dt)
{
$age=$c-$year;
$month=$b-$mon-1;
$f=$dt-$a;
$g=30-$f;
echo
$age."years"." ".$month."Months"." ".$g."Days";
}
if ($b == $mon && $a < $dt )
{
$age=$c-$year-1;
$month=11;
$f=$dt-$a;
$g=30-$f;
echo
$age."years"." ".$month."Months"." ".$g."Days";
}
if ($b == $mon && $a > $dt )
{
$age=$c-$year;
$month=0;
$f=$a-$dt;
echo
$age."years"." ".$month."Months"." ".$f."Days";
}
if ($b < $mon && $a == $dt )
{
$age=$c-$year-1;
$e=$mon-$b;
$month=12-$e;
$f=0;
echo
$age."years"." ".$month."Months"." ".$f."Days";
}
if ($b > $mon && $a == $dt )
{
$age=$c-$year;
$month=$b-$mon;
$f=0;
echo
$age."years"." ".$month."Months"." ".$f."Days";
}
if ($b == $mon && $a == $dt )
{
$age=$c-$year;
$month=0;
$f=0;
echo
$age."years"." ".$month."Months"." ".$f."Days";
}
}
?>
Is This Answer Correct ? | 6 Yes | 3 No |
Post New Answer View All Answers
Which functions are used to count the total number of array elements in php?
Tell me what is the actually used php version?
Which function would you use to replace a record in a database in php?
Who is known as the father of php?
What is the difference between overloading and overriding in php?
Is it possible to protect special characters in a query string?
What is cookie and session in php?
How to execute a php script from the command line?
What are the different loops in php?
Tell us how can we access the data sent through the url with the post method?
What is the function in PHP do not return a timestamp?
What is different between software and app
Tell me is it possible to remove the html tags from data?
What is php dependency injection?
How to store the uploaded file to the final location?