Thread: Age Calculation
View Single Post
  #36  
Old 05-09-2010, 01:36 PM
 
Shamun Shamun is offline
 

X-Adept
  
Join Date: Jun 2009
Location: North Carolina
Posts: 841
 

Default Re: Age Calculation

That's a bit confusing.

Your first statement is checking the years, then your second is checking the months. It's also not an ifelse statement which would be more logical.

In any case...
Code:
function calage() { var curd = new Date(curyear,curmon-1,curday); var cald = new Date(calyear,calmon-1,calday); var diff = Date.UTC(curyear,curmon,curday,0,0,0) - Date.UTC(calyear,calmon,calday,0,0,0); var dife = datediff(curd,cald); if (dife[0]<1) { document.getElementById('dAge').innerHTML = dife[1]+" months, and "+dife[2]+" days"; } else { document.getElementById('dAge').innerHTML = dife[0]+" years, "+dife[1]+" months, and "+dife[2]+" days"; } }



Tested and works.
__________________
- Shane Munroe
Reply With Quote