Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Any function for check if its a leap year ?
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00756383
Message ID:
00756755
Views:
10
>sort of related: Jim, didn't you have a really concise calculation like this for the age?
>
>What about an sql statement where you have the birthdate and you want to create a field for the age?

Ken,

My UDF for calcualting age uses a loop to do the calc.
* GetAge( tdDOB, tdAgeAt)
LOCAL ldDate, lnMonths, lnYears, lnMonths, lcReturn
lnMonths = 0
ldDate = tdDOB
DO WHILE ldDate <= tdAgeAt
  IF GOMONTH(ldDate,12) <= tdAgeAt
     lnYears = lnYears + 12
     ldDate = GOMONTH(ldDate,12)
     LOOP
  ELSE
     EXIT
  ENDIF
ENDDO
DO WHILE ldDate <= tdAgeAt
   lnMonths = lnMonths + 1
   ldDate = GOMONTH(ldDate,1)
ENDDO

IF lnYears > 0 
   IF lnMonths > 0
      lcReturn = TRANSFORM(lnYears) + " years and " + TRANSFORM(lnMonths) + " months"
   ELSE
      lcReturn = TRANSFORM(lnYears) + " years"
   ENDIF
ELSE
   lcReturn = TRANSFORM(lnMonths) + " months"
ENDIF
RETURN lcReturn
Previous
Reply
Map
View

Click here to load this message in the networking platform