Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calculating age
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00086545
Message ID:
00086554
Views:
34
>Hi,
>
>Does any of you have a good and simply routine to calculate the age of a person, depending upon the current date.
>
>
>Thnx in advance
>
>Marc

There's a number of ways to do this. Here's one that's very straight forward.
FUNCTION AgeInYrs

LPARAMETERS pbDate, pcalcDate

LOCAL lbmonth, lncmonth, lnyears, ldcurrdate
IF PCOUNT() > 1
  ldcurrdate = pcalcdate
ELSE
  ldcurrdate = DATE()
ENDIF
lnyears = YEAR(pbdate) - YEAR(ldcurrdate)
IF lnyears > 0
  lnbmonth = MONTH(pbdate)
  lncmonth = MONTH(ldcurrdate)
  IF lncmonth <= lnbmonth
    IF lncmonth < lnbmonth
      lnyears = lnyears - 1
    ELSE
      IF DAY(ldcurrdate) < DAY(pbdate)
        lnyears = lnyears - 1
      ENDIF
    ENDIF
  ENDIF
ENDIF
RETURN lnyears
George

Ubi caritas et amor, deus ibi est
Previous
Reply
Map
View

Click here to load this message in the networking platform