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

Answers were Sorted based on User's Feedback



How to create the PHP Script to Calculate the Age Using the Inputs Of our Birth date and the Curre..

Answer / 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

How to create the PHP Script to Calculate the Age Using the Inputs Of our Birth date and the Curre..

Answer / prakash.matte

<?php
$dob = '29-05-1986';
$age = date('Y') - date('Y', strtotime($dob));
if (date('md') < date('md', strtotime($dob))) {
$age--;
}
echo $age;
?>

Is This Answer Correct ?    5 Yes 2 No

How to create the PHP Script to Calculate the Age Using the Inputs Of our Birth date and the Curre..

Answer / nirav desai

<?php
$a = date('Y',strtotime('1985-10-15'));
$b = date('Y');
$c = $b-$a;
echo "Current age is:: ".$c." Years .";
?>

Is This Answer Correct ?    5 Yes 3 No

How to create the PHP Script to Calculate the Age Using the Inputs Of our Birth date and the Curre..

Answer / sindhujob

No

Is This Answer Correct ?    2 Yes 4 No

How to create the PHP Script to Calculate the Age Using the Inputs Of our Birth date and the Curre..

Answer / king

<?php

//calculate years of age (input string: YYYY-MM-DD)
function birthday ($birthday){
list($year,$month,$day) = explode("-",$birthday);
$year_diff = date("Y") - $year;
$month_diff = date("m") - $month;
$day_diff = date("d") - $day;
if ($day_diff < 0 || $month_diff < 0)
$year_diff--;
return $year_diff;
}

?>

Is This Answer Correct ?    6 Yes 8 No

How to create the PHP Script to Calculate the Age Using the Inputs Of our Birth date and the Curre..

Answer / sandhya

<?php
$date1 = time();
$date2 = mktime(0,0,0,02,01,1979);
$ddif = $date1 - $date2;
$age = floor(($ddif/(60*60*24))/365);
echo $age;
?>

Is This Answer Correct ?    0 Yes 6 No

Post New Answer

More PHP Interview Questions

Difference between mysql_connect and mysql_pconnect?

0 Answers  


What is MVC structure in Magento?

4 Answers  


What does the scope of variables means?

0 Answers  


How many records can be stored in mysql table?

0 Answers  


How variables are passed through arguments?

0 Answers  






I just installed php 5.3.1 in my linux server and now my old work which i used to write with tags is not working at all.. Please help me out.. How can i resolve this??

1 Answers  


Does it possible to compile php with mysql without having mysql sources?

2 Answers  


write a program to print [123] [456] [789] note : braces also need to be printed

2 Answers   Net Solution,


How to use http headers inside php?

0 Answers  


What's the difference between __sleep and __wakeup?

0 Answers  


How to know user has read the email-php?

0 Answers  


What is the difference between the include() and require() functions?

0 Answers  


Categories