<?php /*
   +------------------------------------------------------------------+
   | Green-Beast.com                                                  |
   | PHP: Time Tracker                                                |
   | PHP Hypertext Preprocessor                                       |
   | Copyright Apr 2007                                               |
   | Use with attribution by visible link please!                     |
   | Attribute to: <a href="http://green-beast.com/">Mike Cherim</a>  |
   +------------------------------------------------------------------+
*/
?>

<?php
/*
* SINGLE USE INSTRUCTIONS:
* Place this scriptlet where you want the "age" to show up
* Or you can break out the result from the script if convenient
*/
?>

<?php               // CONFIGURATION
#######################################

  
$start_year  = "1901"; // 4 digits
  
$start_month = "01";   // 2 digits
  
$start_day   = "01";   // 2 digits

#######################################
// No need to edit beyond this point
// Get current data
   
$this_year  = date('Y');
   
$this_month = date('m');
   
$this_day   = date('d');
// Do the basic subtraction
   
$year_age   = $this_year - $start_year;
// Negotiate the day of the month (used below)
if(($this_month == "$start_month") && ($this_day < "$start_day")) {
   
$day_age    = false;
} else {
   
$day_age    = true;
}
// Then negotiate the month of the year to adjust the date properly
if(($this_month >= "$start_month") && ($day_age == true)) {
   
$year_age   = $year_age;
} else {
   
$year_age   = $year_age - 1;
}
// Return the result - This could be un-parsed, the variable relocated, etc.
   
echo('<p>'.$year_age.'</p>');
?>



###########################################################################



<?php
/*
* MULTI-USE (FUNCTION) INSTRUCTIONS:
* Place this scriptlet in a functions file and include it on your pages
* Then use the function calls (far below) to collect and process the variables
*/
?>

<?php // Part 1, the function
function ptt($start_year,$start_month,$start_day) {
// Get current data
    
$this_year  = date('Y');
    
$this_month = date('m');
    
$this_day   = date('d');
// Do the basic subtraction
    
$year_age   = $this_year - $start_year;
// Negotiate the day of the month (used below)
if(($this_month == "$start_month") && ($this_day < "$start_day")) {
    
$day_age    = false;
} else {
    
$day_age    = true;
}
// Then negotiate the month of the year to adjust the date properly
if(($this_month >= "$start_month") && ($day_age == true)) {
    
$year_age   = $year_age;
} else {
    
$year_age   = $year_age - 1;
}
// Return the function's result
return $year_age;
}
?>


<p>I am <?php // Part 2, the function call Y, M, D
                 
echo ptt(1901,01,01); ?> years old.</p>

<p>He is <?php echo ptt(1975,02,08); ?> years old.</p>

<p>She is <?php echo ptt(1992,08,01); ?> years old.</p>