Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Calc age in years+months+days - help, please
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00115698
Message ID:
00115829
Vues:
13
>I need to calculate a person's age in years, months, and days. Is there a function, VCX, or something like that, to do that?
>
>Thanks!
>
>- Gerry
Gerry,

Here's a function to do that;
* CalcAge
LPARAMETERS pdBirth
LOCAL lcRet, ldDate, lnYears, lnMonths, lnDays, ldLastDate
STORE 0 TO lnYears, lnMonths, lnDays
lcRet = ""
ldDate = pdDate
DO WHILE ldDate < DATE()
   lnMonths = lnMonths + 1
   ldLastDate = ldDate
   ldDate = GOMONTH(ldDate,1)
ENDDO
ldDate = ldLastDate
lnYears = IIF(lnMonths>=12,lnMonths/12,0)
lnMonths = lnMonths%12
lnDays = DATE() - ldDate
DO CASE
   CASE lnYears > 0
      lcRet = ALLTRIM(STR(lnYears)) + " Year" + ;
              IIF(lnYears=1," ","s ") + ;
              ALLTRIM(STR(lnMonths)) + " Month" + ;
              IIF(lnMonths=1," ","s ") + ;
              ALLTRIM(STR(lnDays)) + " Day" + ;
              IIF(lnDays=1,"","s")
   CASE lnMonths > 0
      lcRet = "0 Years " + ;
              ALLTRIM(STR(lnMonths)) + " Month" + ;
              IIF(lnMonths=1," ","s ") + ;
              ALLTRIM(STR(lnDays)) + " Day" + ;
              IIF(lnDays=1,"","s")
   OTHERWISE
      lcRet = "0 Years 0 Months" + ;
              ALLTRIM(STR(lnDays)) + " Day" + ;
              IIF(lnDays=1,"","s")
ENDCASE
RETURN lcRet
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform