General information
Category:
Coding, syntax & commands
Try this:
*************
* 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
nBirthYear = year(dBirthDate)
nBirthMonth = month(dBirthDate)
nBirthDay = day(dBirthDate)
nCurYear = year(dTargetDate)
nCurMonth = month(dTargetDate)
nCurDay = day(dTargetDate)
nLastMonth = IIF(nCurMonth = 12,1,nCurMonth-1)
nDaysInMonth = IIF(INLIST(nLastMonth,1,3,5,7,8,10,12),31,;
IIF(INLIST(nLastMonth,4,6,9,11),30,;
IIF(INT(nCurYear/4)=0,28,29)))
nHowManyYears = IIF(nCurMonth > nBirthMonth, nCurYear - nBirthYear, (nCurYear - nBirthYear) -1)
nHowManyMonths = IIF(nCurMonth > nBirthMonth, nCurMonth-nBirthMonth, (12-nBirthMonth) + nCurMonth)
nHowManyDays = IIF(nCurDay > nBirthDay , nCurDay-nBirthDay , (nDaysInMonth-nBirthDay)+nCurDay)
lcReturn = [|]+ALLTRIM(STR(nHowManyYears))+[|]+ALLTRIM(STR(nHowManyMonths))+[|]+ALLTRIM(STR(nHowManyDays))+[|]
return lcReturn
mandy
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only