Re: age

From: Date: Sun, 05 Aug 2001 21:32:11 +0000
Subject: Re: age
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-61355@lists.php.net to get a copy of this message
I've been using this one, which is probably close enough for government work ;) It calculates to a one-month resolution. // Calculates elapsed years between fdate and tdate. // The default for "to date" is today. function elapsed_years($fdate, $tdate=0) { if ($tdate == 0) { $tdate = time(); } $fa = getdate($fdate); $ta = getdate($tdate); // convert dates to number of months since 1900: $fm = $fa["mon"] + (($fa["year"] - 1900) * 12); $tm = $ta["mon"] + (($ta["year"] - 1900) * 12); $em = $tm - $fm; return intval($em/12); } - Tim http://www.phptemplates.org On 06 Aug 2001 03:00:13 +0700, Jon Yaggie wrote: > does any one know where i can get a script that will convert a birthdate in to an age. i have > one half written however i have incounter difficulties with dealing with leap years. perhaps soem > one would know the solution . .. or just a premade script is fine > > > $test = strtotime ("January 12, 1944"); > $test2 = strtotime ("January 9, 1954"); > > $oneyear = 3600 * 24 * 365; > > $diff = $test2 - $test; > $ans = $diff/$oneyear; > > echo $ans; > > > > > > Thank You, > > Jon Yaggie > www.design-monster.com > > And they were singing . . . > > '100 little bugs in the code > 100 bugs in the code > fix one bug, compile it again > 101 little bugs in the code > > 101 little bugs in the code . . .' > > And it continued until they reached 0 > >

« previous php.general (#61355) next »