age calculator using php

Age calculator using PHP

Using simple php and html code we can create a age calculation program.for that you need XAMPP,WAMP or local server in your computer.After starting xampp application you need to create form

<form method="post" action="check_age.php">
    <div class="form-group">
      <label for="date">Date of Birth:</label>
      <input type="date" class="form-control" id="date_of_birth" placeholder="Enter date" name="Dob">
    </div>
    
    <button type="submit" class="btn btn-default">Check Age</button>
  </form>

Then you need to add some php code in check_age.php. The above form action will pass to check_age.php when form button action take place. Mainly i am using to date functions they are date_create() and date_diff().By using these function we can find the age

<?php 
 if(isset($_POST['submit']) {
  $dob=$_POST['dob'];
  $age=date_diff(date_create($dob), date_create('today'))->y;
  echo "Your age is ".$age;
?>

About the author

Junaid V J

My self Junaid . This Blog is a platform to gain immense knowledge of web development. Modern web designing and development can be acquired through this. Specialized in HTML, PHP, CSS, JAVASCRIPT , BOOTSTRAP,WORDPRESS, CODEIGNITER.

View all posts

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *