PHP age calculator script - Mostlikers

13 March, 2014

PHP age calculator script

Find your age using PHP age calculator script. This code easy find your age and calculate total no.of days . try this simple coding make your own age calculator.



Download            Live Demo

PHP

<?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="Total day :".$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="Age is:" . $age;
}
?>

Html

<div style="border: solid #CCC 1px; width:400px; height:100px; margin:auto;">
<form method="post">
<table  align="center" border="0">
  <tr>
    <td>Your Dob Date</td>
    <td><input type="text" value="" placeholder="ex : 20/10/1995" name="dob" /></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><input type="submit" value="Calcualte" name="sub" /></td>
  </tr>
</table>
<span style="color:#C00;"><h3><?php if(isset($_POST['sub']))
{  echo $dobs; ?>  <?php echo $days;  } ?></h3></span>
</form>
</div>

No comments:

Post a Comment