Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Age Calculation
Message
De
12/08/2000 10:04:44
Cindy Winegarden
Duke University Medical Center
Durham, Caroline du Nord, États-Unis
 
 
À
12/08/2000 10:02:36
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Divers
Thread ID:
00403635
Message ID:
00404310
Vues:
13
Thanks.

>I think Rick's is somewhat similar to this. You might keep as a reference. In fact it was longer to assume what value to return (was designed for pediatrics:) and was expressing age with a notation like '23/365', '3/12' or '16'. Honestly I lost the longer version :
>
*************
>* AgeInYMD
>* Parameters :
>* date DateOfBirth,
>* date TargetDateToCalculateAge (If not passed date() assumed),
>*
>* return : Character - Age in YYYYMMDD format
>*************
>
>*function AgeInYMD
>LPARAMETERS dBirthDate, dTargetDate
>IF parameters() < 1
>    RETURN {}
>ENDIF
>IF empty(dTargetDate)
>    dTargetDate = date()
>ENDIF
>
>nYears = year(dTargetDate)-year(dBirthDate)
>
>IF gomonth(dBirthDate,nYears*12) > dTargetDate
>    nYears = nYears - 1
>ENDIF
>
>dBirthDate = gomonth(dBirthDate,nYears*12)
>
>nMonths = 0
>
>DO while month(dBirthDate) # month(dTargetDate)
>    dBirthDate = gomonth(dBirthDate,1)
>    nMonths = nMonths + 1
>ENDDO
>
>IF day(dBirthDate) > day(dTargetDate)
>    nMonths = nMonths - 1
>    dBirthDate = gomonth(dBirthDate,-1)
>ENDIF
>
>nDays = dTargetDate - dBirthDate
>
>RETURN padl(int(nYears * 10^4 + nMonths * 10^2 + nDays),8,'0')
Cetin

>
>>Rick - I could have used that awhile back. Exact age is not an easy calculation to get right. Here in Peds we usually report ages in years and months when we do statistics, and I spent a whole afternoon getting my function to come out right!
>>
>>I'll be using yours next time I need one!
>>
>>
>>>The one- and two-liners are OK if you're not worried about being exactly right all the time. If you need more precision, I posted an AGE function that returns the exact age in years, months, and days. You can find it in the UT files section, and also on the FoxPro Developers' page of my web site (see the link in my sig line).
>>>
>>>>Is there a simple VFP age calculation Function ? EX: something like AGECALC({date1},{date2}) ?
>>>>
>>>>Thanks for your help
>>>>Stephen J. Hunt
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform