Calculating a delta of years from a date
Posted
by Spiros
on Stack Overflow
See other posts from Stack Overflow
or by Spiros
Published on 2010-06-16T16:48:41Z
Indexed on
2010/06/17
10:53 UTC
Read the original article
Hit count: 257
I am trying to figure out a way to calculate the year of birth for records when given the age to two decimals at a given date - in Perl.
To illustrate this example consider these two records:
date, age at date
25 Nov 2005, 74.23
21 Jan 2007, 75.38
What I want to do is get the year of birth based on those records - it should be, in theory, consistent. The problem is that when I try to derive it by calculating the difference between the year in the date field minus the age, I run into rounding errors making the results look wrong while they are in fact correct.
I have tried using some "clever" combination of int() or sprintf() to round things up but to not avail. I have looked at Date::Calc but cant see something I can use.
p.s. As many dates are pre-1970, I cannot not unfortunately use UNIX epoch for this.
© Stack Overflow or respective owner