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
What is the difference between array_map () and array_shift ()?
Is php 7 backwards compatible?
What is php call function?
What is the best php version for wordpress?
Why shouldn't I use mysql_* functions in php?
What are the advantages of stored procedures, triggers, indexes in php?
What are the functions used in php?
What can php do?
What are the array functions in php?
What is php trait?
What are php applications?
Explain what is the difference between for and foreach?
How come the code works, but does not for two-dimensional array of mine?
What are the 3 scope levels available in php and how would you define them?
What is isset in php?