WITH CREATEOBJECT("age") .CalcAge({^1988/2/29} , {^2006/9/14 }) CLEAR * Observed : 18,6,15 * Expected : 18,6,17 ? .Years , .Months , .Days * CHECK with the correct definition Age = (((Birth+Y)+M)+D) ? GOMONTH(GOMONTH({^1988/2/29},.Years*12),.Months)+.Days * CHECK with a bad definition ? GOMONTH({^1988/2/29},.Years*12+.Months)+.Days * none definition can return {^2006/9/14 } ENDWITH *!* oAge = createobject('Age') *!* ldBirth = {^1961/1/19} *!* ldTarget = date() && How old is he today. *!* oAge.CalcAge(ldBirth, ldTarget) *!* ? oAge.Years, oAge.Months, oAge.Days define class age as relation Years=0 Months=0 Days=0 procedure CalcAge lparameters tdBirth, tdTarget local ldTemp, ldBirth, lnDrop if tdBirth > tdTarget ldTemp = tdTarget tdTarget = tdBirth tdBirth = ldTemp endif ldBirth = date(year(tdTarget),month(tdBirth),day(tdBirth)) lnDrop = 0 if empty(ldBirth) && leap case ldBirth = date(year(tdTarget),3,1) lnDrop = iif(month(tdTarget)<=2,0,1) endif with this .Years = year(tdTarget) - year(tdBirth) - (iif(ldBirth > tdTarget,1,0)) .Months = (month(tdTarget) - month(tdBirth) + 12 - ; (iif(day(tdBirth)>day(tdTarget),1,0)))%12 .Days = tdTarget - gomonth(tdBirth,.Years*12+.Months) - lnDrop endwith endproc enddefine