Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Calculating a persons age based on their birthday.

by Maqs (Deacon)
on May 03, 2000 at 14:12 UTC ( #10068=note: print w/ replies, xml ) Need Help??


in reply to Calculating a persons age based on their birthday.

As far as I understand, you would like to know the number of full years the person is alive?
So, assuming you have only the number of day, we can do the following:
---
my $year = (localtime)[5]+1900;
my $fullyears=0;
$nod = xxxx; #number of days goes here...
while ($nod > 365)
{ if ( $year % 4) {$nod=$nod-365} else {$nod=$nod-366}; #check for the leap year.
$year--; $fullyears++;
};

print "$fullyears\n";
---
Rather simple but m.b. not so gracefull solution :) You see, you do not need any special modules.


Comment on Re: Calculating a persons age based on their birthday.
RE: Re: Calculating a persons age based on their birthday.
by t0mas (Priest) on May 03, 2000 at 14:18 UTC
    Sholdn't the
    if ($year % 4) {$nod=$nod-365} else {$nod=$nod-366}; #check for the le +ap year.
    be
    if ((($year % 4 == 0) && ($year % 100 != 0)) || ($year % 400) == 0) {$ +nod=$nod-365} else {$nod=$nod-366}; #check for the leap year.
    To handle Y2K (and others) correct... /t0mas
      Sorry - It should be
      if ((($year % 4 == 0) && ($year % 100 != 0)) || ($year % 400) == 0) {$ +nod=$nod-366} else {$nod=$nod-365}; #check for the leap year.
      365 and 366 swiched places....
        don't think so. The check might be simple. if $year % 4 gives any result except '0'
        then this is not a leap year. there is nothing else to check out, IMHO.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://10068]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (10)
As of 2015-07-06 23:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (85 votes), past polls