[PHP] Age

2002-02-09 Thread André Felix Miertschink

Could anybody find out the simplest method of calculating the age?
The date of birth is in the format string ('01/01/1977').

André


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] age

2001-08-05 Thread Jon Yaggie

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





Re: [PHP] Age

2002-02-09 Thread Edward van Bilderbeek - Bean IT

don't know if there is some "date_diff" -like function, but you can do it
this way:

$now = getdate();
$nw_year = $now["year"];
$nw_month = $now["mon"];
$nw_day = $now["mday"];

$chk_date = "09/02/1977";
list ($chk_day, $chk_month, $chk_year) = explode("/", $chk_date);

print $nw_year;
$age = $nw_year - $chk_year;
if ($nw_month<$chk_month) $age--;
if ($nw_month==$chk_month && $nw_day<$chkday) $age--;

print "age: ".$age;



assuming that the date : "dd/mm/"

greets,

edward


- Original Message -
From: "André Felix Miertschink" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, February 09, 2002 8:08 PM
Subject: [PHP] Age


> Could anybody find out the simplest method of calculating the age?
> The date of birth is in the format string ('01/01/1977').
>
> André
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] age

2001-08-05 Thread Corey Chapman

Here's something I use for a date string that looks like mm/dd/ to 
turn the date into an age from the current date.

$age = explode("/", $bdate);
$userage = date("Y") - $age[2];
if($age[0] > date("m") || ( $age[0] == date("m") && $age[1] > date
("d"))) { --$userage; }
if($userage > 50) { $userage = ""; }

I did not compensate for leap years, however. You could use my code, 
and it should work fine, but the first line where I do an explode, 
you'd have to change that to turn your date string into #'s like I 
use.. 

> 
> 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
> 
> 
> 
> 

Corey Chapman
Xnull CEO
(Chat with us: http://forum.xnull.com)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] age

2001-08-05 Thread Tim

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
> 
> 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] age

2001-08-05 Thread Jan Wilson

* Jon Yaggie <[EMAIL PROTECTED]> [010805 16:35]:
> 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

This is one of those problems that sounds easy ... until you get into
it.  It is leap years that make it messy.  Try this ... it worked on
all the dates I threw at it, and has options for whether you want just
the year or a fraction, and the fraction can be decimal or days:

function age($birthdate) {
// $birthdate can be most any format
$bornUnix = strtotime($birthdate);
$born = getdate($bornUnix);
$todayUnix = time();
$today = getdate();
$last = array('year' => $today['year'], 'mon' => $born['mon'], 
'mday'=>$born['mday']);
$next = $last;
if ($today['mon'] < $born['mon']) {
// before birthday
$last['year'] -= 1;
} elseif ($today['mon'] > $born['mon']) {
// after birth month
$next['year'] += 1;
} else {
// in birth month
if ($today['mday'] < $born['mday']) {
// before birthday
$last['year'] -= 1;
} elseif ($today['mday'] > $born['mday']) {
// after birthday
$next['year'] += 1;
} else {
// happy birthday
$next['year'] += 1;
}
}
$age = $last['year'] - $born['year'];
// set $yearFraction to TRUE if you want fractional days
$yearFraction = TRUE;
if ($yearFraction) {
// set $yearDecimals to number of decimals desired
$yearDecimals = 3;
$lastUnix = mktime(0,0,0,$last['mon'],$last['mday'],$last['year']);
$nextUnix = mktime(0,0,0,$next['mon'],$next['mday'],$next['year']);
$daysThisYear = ($nextUnix-$lastUnix)/(24*60*60);
$daysSinceLast = ($todayUnix-$lastUnix)/(24*60*60);
if ($yearDecimals > 0) {
// give decimal fraction
$age += $daysSinceLast/$daysThisYear;
$age = number_format($age,$yearDecimals);
} else {
// give actual fraction
$age .= " " . number_format($daysSinceLast,0) . "/" . 
number_format($daysThisYear,0);
}
}
return $age;
}

-- 
Jan Wilson, SysAdmin _/*];  [EMAIL PROTECTED]
Corozal Junior College   |  |:'  corozal.com corozal.bz
Corozal Town, Belize |  /'  chetumal.com & linux.bz
Reg. Linux user #151611  |_/   Network, SQL, Perl, HTML


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]