Age-Calculator



Download

In This tutorial we can calculate our ages by enter our Date Of Birth into textbox


<?php

if(isset($_POST['sub']))
{
date_default_timezone_set ("Asia/Calcutta");
$dateofreg1=date("d M Y");
$dbd=$_POST['dob'];
$startTimeStamp = strtotime($dbd);
$endTimeStamp = strtotime($dateofreg1);
$timeDiff = abs($endTimeStamp - $startTimeStamp);
$numberDays = $timeDiff/86400;
$numberDays = intval($numberDays);
$days="Days :".$numberDays;
$birthDate =$dbd;
$birthDate = explode("/", $birthDate);
$age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md")
? ((date("Y") - $birthDate[2]) - 1)
: (date("Y") - $birthDate[2]));
$dobs="Your Age is:" . $age;
}

?>

//Here you can enter Your Date of birth

<input type="text" name="dob" >
<input type="submit" value="Calculate" name="sub" >

//This code for Display Age and Total Days


<?php if(isset($_POST['sub']))
{ echo $dobs; ?> <?php echo $days; } ?>


No comments: