Php Code for Age

This php programming code is used to find the age . You can select the whole php code by clicking the select option and can use it. When you click text, the code will be changed to text format. This php program code will be opened in a new pop up window once you click pop-up from the right corner. You can just copy, paste this php code and use it to find the age .

<?php
error_reporting(0);
function leapYearFeb($year, $mon) //Leap year checking
{
    $flag = 0;
    if ($year % 100 == 0) 
    {
        if ($year % 400 == 0) 
        {
            if ($mon == 2) 
            {
                $flag = 1;
            }
        }
    } 
    else if ($year % 4 == 0) 
    {
        if ($mon == 2) 
        {
            $flag = 1;
        }
    }
    return ($flag);
}
 $daysInMon = array(31, 28, 31, 30, 31, 30,31, 31, 30, 31, 30, 31);  

$day=12;
$month=8;
$year=1992;

echo "\nDate of Birth: ".$day. "/" .$month. "/" .$year;

echo "\nCurrent Date: ".date("d"). "/" .date("m"). "/" .date("Y");

if (leapYearFeb($year, $month)) //Checking the given year Leap or not
{
    $days = $days + 1;
}
    $days1 = $days + date("d");
    $month1 = (12 - $month) + date("m");
    $year1 = date("Y")- $year-1;

if (leapYearFeb(date("Y"), (date("m") + 1))) 
{
    if ($days >= ($daysInMon[date("m")] + 1)) 
    {
        $days = $days - ($daysInMon[date("m")] + 1);
        $month = $month + 1;
    }
} 
else if ($days >= $daysInMon[date("m")]) 
{
    $days = $days - ($daysInMon[date("m")]);
    $month = $month + 1;
}

if ($month >= 12) 
{
    $year = $year + 1;
    $month = $month - 12;
}

echo "\nAge :" .$year1."years". $month1. "months" .$days1."days";

?>
Other Programming Codes
Online Calculator : Age Calculator
Click on the select code link to copy and paste this free php program code for age calculator.

english Calculators and Converters


Sitemap