Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What is best way to calculate age
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01155605
Message ID:
01155682
Views:
29
>I never need to calculate ages, but here what I invent :-)) (I hate endless loops)
>
>ldBegin = DATE(1965, 4, 26)
>ldEnd   = DATE()
>STORE 0 TO lnYear, lnMonhts, lnDays
>DO WHILE .t.
>   DO CASE
>      CASE GOMONTH(ldBegin,12) <= ldEnd
>           lnYear = lnYear + 1
>           ldBegin = GOMONTH(ldBegin, 12)
>      CASE GOMONTH(ldBegin,1) <= ldEnd
>           lnMonhts = lnMonhts + 1
>           ldBegin  = GOMONTH(ldBegin, 1)
>      CASE ldBegin            < ldEnd
>           lnDays  = lnDays  + 1
>           ldBegin = ldBegin + 1
>   OTHERWISE
>           EXIT
>   ENDCASE
>ENDDO
>? lnYear, lnMonhts, lndays
>
>Of couse there is no checking for valid date period and no error handling at all. Also not well tested :-)))

The first very serious problem this code has is lnMonths is spelled wrongly <g>

Add a back date calculation to your code to see, if the dates match.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform