3+ PHP Age Calculator Programs

This post contains a total of 3+ PHP Age Calculator Program Examples with Source Code. All these Age Calculator Programs are made using PHP.

You can use the source code of these examples with credits to the original owner.

Related Posts

PHP Age Calculator Programs

1. Age Calculator Program

Made by Chihi Moez. Source

You are still 26 years old.
<?php

// EDIT ONLY THESE 3 VALUES
$day = 30;
$month = 9;
$year = 1995;

$birthday = $day . $month;
$thisMonthAndYear = date("jn");
$thisYear = date("Y");

$subtraction = $thisYear - $year;

if ($thisMonthAndYear >= $birthday) {
   echo "You are ". $subtraction ." years old.";
}
else {
   echo "You are still ". --$subtraction ." years old.";
}

?>

2. PHP Age calculator

Made by WadeQ. Source

Its not yet your birthday Derrick Wadek, you are 34 years old.

<?php

         
    $dob = "20-12-1987" ;
    
    $name = "derrick wadek" ;
    
    $name = ucwords($name) ;
    
    
    //list the dates separately
    
    list ($day, $month, $year) = explode("-" , $dob) ;
    
    //retrieve current dates
    
    $curday = date('d');
    $curmonth = date('m');
    $curyear = date('Y');
    
    $age = $curyear - $year;
    
    $age-- ;
    
    if($curmonth > $month || $curmonth == $month && $curday >= $day) {
        
        $age++ ;
    }
    
    else if($curmonth == $month && $curday == $day) {
    
    echo "Happy birthday ".$name.", you are ".$age." years old!" ;
        
    } 
    
    else if($curmonth != $month && $curday != $day) {
        
        echo "Its not yet your birthday ".$name.", you are ".$age." years old.";
} 
  
?>

3. Age Calculator by Grdr

Made by Grdr. Source

21 years, 8 months, 0 days.
<?php

function getAge($birthday) {
    $birthday = explode(".", $birthday);
    $birthday = mktime(0, 0, 0, $birthday[1], $birthday[0], $birthday[2]);
    $years = time() - $birthday;
    
    $years /= 60 * 60 * 24 * 365.25; // approximation, should be fine
    $months = ($years - intval($years)) * 12;
    $days = ($months - intval($months)) * 30.4375; // approximation, might be off by a few hours
    
    // seeing as days are already inaccurate, the values below are very unreliable
    $hours = ($days - intval($days)) * 24;
    $minutes = ($hours - intval($hours)) * 60;
    $seconds = ($minutes - intval($minutes)) * 60;
    
    echo intval($years) . " years, " . intval($months) . " months, " . intval($days) . " days." 
    // . " " . intval($hours) . " hours, " . intval($minutes) . " minutes and " . intval($seconds) . " seconds."
    ;
}

$mybirthday = "24.12.2000";
echo getAge($mybirthday);

?>

4. Age Calculator

Made by Jeremy Luman. Source

Jeremias , Erika Your age is: 30
<?php
$myfile = fopen("names.txt", "w");

  $txt = "Jeremias\n";
   fwrite($myfile, $txt);
  $txt = "Erika\n";
   fwrite($myfile, $txt);

 fclose($myfile);

$read = file('names.txt');
$count = count($read);
  $i = 1;
foreach ($read as $line) {
  echo $line;
   if($i < $count) {
      echo ', ';
      }
     $i++;
   }
   
//date formatted in mm/dd/yyyy format
$birthDate = "09/19/1991"; 
//explode the birthdate to get month, day and year 
$birthDate = explode("/", $birthDate); 
//get the age from date or 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])); 
echo "Your age is: " . $age; 

?>