>************* >* AgeInYMD >* Parameters : >* date DateOfBirth, >* date TargetDateToCalculateAge (If not passed date() assumed), >* >* return : Character - Age in YYYYMMDD format >************* > >LPARAMETERS dBirthDate, dTargetDate >IF parameters() < 1 > RETURN {} >ENDIF >IF empty(dTargetDate) > dTargetDate = date() >ENDIF > >nYears = year(dTargetDate)-year(dBirthDate) > >IF gomonth(dBirthDate,nYears*12) > dTargetDate > nYears = nYears - 1 >ENDIF > >dBirthDate = gomonth(dBirthDate,nYears*12) > >nMonths = 0 > >DO while month(dBirthDate) # month(dTargetDate) > dBirthDate = gomonth(dBirthDate,1) > nMonths = nMonths + 1 >ENDDO > >IF day(dBirthDate) > day(dTargetDate) > nMonths = nMonths - 1 > dBirthDate = gomonth(dBirthDate,-1) >ENDIF > >nDays = dTargetDate - dBirthDate > > >lcReturn = [|]+ALLTRIM(STR(nYears))+[|]+ALLTRIM(STR(nMonths))+[|]+ALLTRIM(STR(nDays))+[|] > >RETURN (lcReturn) >
lparameters tdDate1, tdDate2 local lnYears, lnMonths, lnDays, ldTemp, ldCalcDate IF parameters() < 1 RETURN replicate('0',8) ENDIF tdDate2 = IIF(empty(tdDate2),date(),tdDate2) if tdDate2 < tdDate1 ldTemp = tdDate1 tdDate1 = tdDate2 tdDate2 = ldTemp endif lnMonths = floor((tdDate2-tdDate1)/31) ldCalcDate = gomonth( tdDate1, lnMonths ) if ldCalcDate > tdDate2 ldCalcDate = tdDate1 lnMonths = lnMonths - 1 endif do while gomonth( ldCalcDate, 1 ) <= tdDate2 ldCalcDate = gomonth( ldCalcDate, 1 ) lnMonths = lnMonths + 1 enddo lnYears = int( lnMonths / 12 ) lnMonths = lnMonths - ( lnYears * 12 ) lnDays = tdDate2 - ldCalcDate RETURN trans(int(lnYears * 10^4 + lnMonths * 10^2 + lnDays),'@R 9999/99/99')Cetin