Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reliably getting age from DOB and DATE()
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00586710
Message ID:
00586718
Vues:
16
>I have run into an interesting issue. We have been using the following line for some time to give the age of a person.
>
>
>ALLTRIM(STR(INT((DATE()-This.Value)/365.25)))
>
>
>However, on the birthday, on many years it's off by one day (wrong value on the birthday, but correct the next day).
>
>Is there an easy way to always get the age right with a single line of code? If not, what block of code would it take to accomplish this?

Maybe a little unorthodox. But it makes sense to me :)
nAge= YEAR(ldDate) - YEAR(ldDob) - IIF(GOMONTH(ldDob, (YEAR(ldDate) - YEAR(ldDob)) * 12) > ldDate, 1, 0)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform