IMHO a better way to tell if someone's age in years is to calc this way:
use integer; # speeds up the math my @date = localtime(time); # convert year to months and add current number of months my $yearnow = ((($date[5] + 1900) * 12) + ($date[4] + 1)); print "Enter an 8 digit birthdate. eg: 01/01/1970\n"; my ($monththen, $daythen, $yearthen) = split /\//, <STDIN>; # we'll fly without error-checking now and just add what they e +ntered for month my $modyearthen = (($yearthen * 12) + ($monththen)); # subtract the totals and divide by 12, convert to int (redunda +nt for safety sake) # and voila actual number of years alive $numyears = int (($yearnow - $modyearthen)/12); print "You've been around $numyears years!\n";

This way, you are also accounting for the months. For example, I was born in
August, and if you just subtract the years from each other right now, it says I'm 25,
which isn't right. You need to account for the total number of months, and then take
the integer part of the division by 12 which gives you the year and remainder. It's more
work, but it's a hair more accurate. Certainly for the sake of accuracy, you could take
it down to days...but I'll leave that to someone else! :)

In reply to Re: Calculating a persons age based on their birthday. by buzzcutbuddha
in thread Calculating a persons age based on their birthday. by artful

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.