Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Age to Years,Month,Day - Problem With
Message
From
10/09/2002 17:35:27
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00699014
Message ID:
00699081
Views:
23
This message has been marked as the solution to the initial question of the thread.
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
Map
View

Click here to load this message in the networking platform