note 38682 deleted from function.date by nlopess
| From: | nlopess@php.net | Date: | Fri, 02 Jan 2004 20:10:06 +0000 |
| Subject: | note 38682 deleted from function.date by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-62811@lists.php.net to get a copy of this message | ||
Note Submitter: Tomislav Drpic - www.ilatina.com/tdrpic/
----
I have the following solution to calculate a person's age:
<?php
/**
* Get the current age of a person
* @author DRPIC, Tomislav - www.ilatina.com/tdrpic/
* @param integer $year
* @param integer $month
* @param integer $day
*/
function getAge($year, $month, $day) {
// get plain year difference
$today = getdate();
$age = $today["year"] - $year;
// get day in year from birthday and today
// date("z") : z - day of the year; i.e. "0" to "365"
$bday_count = date("z", mktime(0, 0, 0, $month, $day, $today["year"]));
$today_count = date("z");
// check if we are before or after birthday day
if ($bday_count > $today_count) {
$age--;
}
return $age;
}
?>
This solution solves the problem of using "negative" dates under Windows.
Hope it helps.