Re: determining age from birthdate

From: Date: Wed, 29 Nov 2000 22:50:47 +0000
Subject: Re: determining age from birthdate
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-27899@lists.php.net to get a copy of this message
On Wednesday 29 November 2000 16:22, Paul Tuohy wrote: > I have all the parts of a birth date and i want to determine the present > age of the person submitting the data. How can I do this with PHP? > > the birth date info comes to me in this form: > > Year: 'yyyy' > month: 'mm' > day: 'dd' > ___________________________________________________________________________ Here is a snip of (awful) code I wrote to do what you are wanting. Perhaps you can improve on it and adapt it for you usage: if($u->birthday) { ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})", $u->birthday, $br); // $birthday = date("D,Md,Y", mktime(0,0,0, $br[2], $br[3], $br[1]) ); ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})", date("Y-m-d", time()), $today); for($i = 1; $i < 4; $i++) { settype($br[$i], "integer"); settype($today[$i], "integer"); } $age = $today[1] - $br[1] - 1; if( ($today[2] > $br[2]) || ($today[2] == $br[2] && $today[3] >= $br[3]) ) $age = $age + 1; $username .= "/{$age}"; // $username .= "(<FONT SIZE=-1>{$birthday}</FONT>)"; >__________ Get more from the Web. FREE MSN Explorer download : > http://explorer.msn.com -- -------- Robert B. Easter reaster@comptechnews.com --------- - CompTechNews Message Board http://www.comptechnews.com/ - - CompTechServ Tech Services http://www.comptechserv.com/ - ---------- http://www.comptechnews.com/~reaster/ ------------

« previous php.general (#27899) next »