Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Age to Years,Month,Day - Problem With
Message
De
10/09/2002 17:35:27
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00699014
Message ID:
00699081
Vues:
22
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform