DayLaborer
Programmer
I have the following function:
to which I'm passing a date, for example: 10/1/1989 The problem is that it returns the same age regardless of whether the "person" has his/her birthday this year already or not.
For example, if today (10/2/2009) I want to check the age of two people: one born on 10/1/1989 and another born on 10/3/1989, the result "20" is returned for both.
What's wrong with this function?
Thanks much,
Eliezer
Code:
function ageInYears(bDay)
{
//based on: [URL unfurl="true"]http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20664053.html[/URL]
now = new Date()
bD = bDay.split('/');
if(bD.length==3)
{
born = new Date(bD[2], bD[1]*1-1, bD[0]);
years = Math.floor((now.getTime() - born.getTime()) / (365.25 * 24 * 60 * 60 * 1000));
return years;
}
}
For example, if today (10/2/2009) I want to check the age of two people: one born on 10/1/1989 and another born on 10/3/1989, the result "20" is returned for both.
What's wrong with this function?
Thanks much,
Eliezer