Calculate the number of days a person was alive on his Nth birthday? (Summer task)

Possible duplicate:
How to calculate a person’s age in a year, month, days?

How to calculate the number of days during which a person was alive on his N-th birthday? given his month of birth, day, year, and age? How to solve the problem of a leap year?

0
source share
1 answer

Here a (view a) is single-line 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 discards the calculations of the key leap year of the function POSIX::mktime.

+1
source

Source: https://habr.com/ru/post/1716950/


All Articles