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
Explain me what is the meaning of a persistent cookie?
What is file upload?
Which function would you use to read a line of data from a file in php?
Write a program to find the factorial of a number in php?
What is singleton pattern in php?
Which MySQL function would you use to select a database?
What is form submission?
What is a PHP accelerator?
Explain the importance of the function htmlentities.
What is php how it works?
How to Pass JSON Data in a URL using CURL in PHP?
Are static variables final?
What is config file in php?
What is a null coalescing operator in php7?
what is the use of include_once in php?