Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calc age in years+months+days - help, please
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00115698
Message ID:
00115829
Views:
14
>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
Previous
Reply
Map
View

Click here to load this message in the networking platform