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

What is the difference between array_map () and array_shift ()?

519


Is php 7 backwards compatible?

602


What is php call function?

504


What is the best php version for wordpress?

530


Why shouldn't I use mysql_* functions in php?

598






What are the advantages of stored procedures, triggers, indexes in php?

510


What are the functions used in php?

509


What can php do?

552


What are the array functions in php?

530


What is php trait?

526


What are php applications?

516


Explain what is the difference between for and foreach?

537


How come the code works, but does not for two-dimensional array of mine?

507


What are the 3 scope levels available in php and how would you define them?

514


What is isset in php?

532