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

How to redirect a url from http to https in .htaccess?

0 Answers  


What is php used for?

0 Answers  


What is cookies? How to create cookies in php?

0 Answers  


In mail($param1, $param2, $param3, $param4), the $param2 contains__

1 Answers  


What is symfony php?

0 Answers  






Do you know what is php?

0 Answers  


What is strlen php?

0 Answers  


Which function would you use to merge two arrays in php?

0 Answers  


What is binary safe function in php?

0 Answers  


suppose if u want to pass session value using cookies onlu.. what changes i've to made in php.ini file?

1 Answers  


Tell me how do you define a constant?

0 Answers  


Where is session value stored php?

0 Answers  


Categories