How to make Age Counter through PHP ?

Description:- Through this example you can easily find out how many years, how many months, and how many days old are you. Just select the date and click on the button and it will reveal how exactly old are you.

//Defining variables in which we'll store the values of the given HTML fields
$mm = $_REQUEST['month']; 
$yy = $_REQUEST['year'];

//Defining variables in which we'll insert the current date
$zzz = date_create("$ry-$rm-$rd");

// Through date_diff() function we can calculate the difference of $ddd & &zzz
$dif = date_diff($ddd,$zzz);
$day= $dif->d;
$mon = $dif->m;
$yr = $dif->y;

$msg="You are exactly $yr years, $mon months & $day day old.";
<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<form action="<?php echo $_PHP_SELF; ?>" method="post">
    <select name="day">
        <option selected>Day </option>
                for($a=1; $a<=31; $a++)
                    echo "<option value=$a>".$a."</option>";
        <select name="month">
            <option selected>Month</option>
            $month=array("Jan", "Feb", "Mar", "April", "May", "June", "July", "Aug", "Sep", "Oct", "Nov", "Dec");
                foreach($month as $m)
                    echo "<option value=$m>".$m."</option>";
        <select name="year">
            <option selected>Year</option>
                for($b=1970; $b<=2015; $b++)
                    echo "<option value=$b>".$b."</option>";
<input type="submit" name="sub" value="Tell me how old I'm? "/>
<h1 style="color:rgba(0,102,255,1)"><?php echo $msg; ?> </h1>

One thought on “How to make Age Counter through PHP ?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s