Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Age function or algorithm?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00169602
Message ID:
00169618
Vues:
25
>Does someone have a routine that calculates someones's age based upon the current date?
>
>I have written one, but it does not account for leap years so it's basically useless and I don't want to reinvent the wheel. It's probably a common routine out there.
>
>Thanks for helping me again.

How does leap year come into play when calculating age? All you need to do is find out how many years have passed since the birth year... Then, if the current date is before the person birthday for this year, subtract one.
Function age( pdBirthDate )

local ldBirthDay,lnAge

set century on

* calculate this years birth day
ldBirthDay = ctod( '^'+str(year(date()),4)+'/'+str(month(pdBirthDate),2)+'/'+str(day(pdBirthDate),2) )

* years since birth year...
lnAge = year( date() ) - year( pdBirthDate )

* adjust if birthday hasn't occured this year yet...
if ldBirthDay > date()
	lnAge = lnAge - 1
endif

return lnAge
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform