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
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"." ".$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 |
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 |
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 |
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 |
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 |
i have designed a registration form in html (registration.html) and to insert user details in database i have designed a submit form in php (submit_registration.php) but when i click on submit button in registration.html it opens a dialogue box which asks for open or save php(submit_registration.php) even though i have already installed apache HTTP server and php version 5 on my computer and i am using mysql as backend. plz suggest me what should i do????
Do you know how can we check the value of a given variable is a number?
How to pass variables by references?
Under what circumstance is it impossible to assign a default value to a parameter while declaring a function?
Explain the syntax for ‘foreach’ loop with example.
Tell me how a constant is defined in a php script?
when will be syndicate bank written exam ? i need the date of exam
Why overriding is called runtime polymorphism?
What are the differences between GET and POST methods in form submitting?
Is php a mvc?
How to copy a file?
How to redirect a url from http to https in .htaccess?