views:

141

answers:

2

How to calculate the number of days that person has been alive on his Nth birthday? given his birth month, day, year, and his age? How to solve the leap year challenge?

+2  A: 

Hi metashockwave, see this link

http://stackoverflow.com/questions/453208/how-can-i-calculate-the-age-of-a-person-in-year-month-days

Bye.

RRUZ
+1  A: 

Here's a (sort of a) one-liner in Perl:

$ perl -MPOSIX -e '($d, $m, $y, $a) = @ARGV; print ((mktime(0,0,0,$d,$m+1,$y+$a-1900) - mktime(0,0,0,$d,$m+1,$y-1900)) / 86400)' 23 4 1975 29
10593

Of course, this passes off the key leap year calculations to the POSIX::mktime function.

Greg Hewgill