note 39927 deleted from function.date by kennyt

From: Date: Sun, 18 Jul 2004 17:25:35 +0000
Subject: note 39927 deleted from function.date by kennyt
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-73507@lists.php.net to get a copy of this message
Note Submitter: spoonman ---- I was fed up with trying to figure out birthdays. The leap year codes always messed things up. Those always seem to calculate age based on number of days between A and B. This is simple math between the two different years. if the birthday is coming up, we subtract 1 year so they don't magically get 1 year older. The code below could of been shortend but was done this way for personal reasons. I use the following to calculate age, it works. i've tested it. PS birthdate I store in epoch format. function age($born) { $topofthehour = mktime(0,0,0,date("m"),date("d"),date("Y")); if(mktime(0,0,0,date("m",$born),date("d",$born), date("Y",$topofthehour)) == $topofthehour){ #Today Is Their Birthdate return ( date("Y",$topofthehour) - date("Y", $born) ); }elseif(mktime(0,0,0,date("m",$born),date("d",$born), date("Y",$topofthehour)) > $topofthehour){ #Birthdate Is In The Future $calc = (date("Y",$topofthehour) - date("Y", $born) - 1); return $calc; }else{ #Birthdate Has Passed $calc = (date("Y",$topofthehour) - date("Y", $born)); return $calc; } }

« previous php.notes (#73507) next »