note 38682 added to function.date

From: Date: Fri, 02 Jan 2004 19:04:27 +0000
Subject: note 38682 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-62801@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38682 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38682&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38682&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#62801) next »