usage: userAge = returnAge("1","January","1974");
function returnAge(dd,mm,yy) {
months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
birthday = new Date(mm + "" + dd + "," + yy);
today = new Date();
diff = today-birthday;
birthdayJulian = getJulianDay(dd,mm);
todayJulian = getJulianDay(today.getDate(),months[today.getMonth()]);
todayJulian<birthdayJulian?addDays = 365+(birthdayJulian - todayJulian):addDays=365;
diff = diff/1000/60/60/24/addDays;
return Math.floor(diff);
}
function getJulianDay(dd,mm) {
mDate = new Date();
mYear = mDate.getYear();
mStart = new Date("January 1, " + mYear);
mEnd = new Date(mm + " " + dd + "," + mYear);
mSpan = mEnd - mStart;
mSpan = mSpan/1000/60/60/24;
return mSpan;
}
slayer.office home