Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Reliably getting age from DOB and DATE()
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00586710
Message ID:
00586718
Views:
12
>I have run into an interesting issue. We have been using the following line for some time to give the age of a person.
>
>
>ALLTRIM(STR(INT((DATE()-This.Value)/365.25)))
>
>
>However, on the birthday, on many years it's off by one day (wrong value on the birthday, but correct the next day).
>
>Is there an easy way to always get the age right with a single line of code? If not, what block of code would it take to accomplish this?

Maybe a little unorthodox. But it makes sense to me :)
nAge= YEAR(ldDate) - YEAR(ldDob) - IIF(GOMONTH(ldDob, (YEAR(ldDate) - YEAR(ldDob)) * 12) > ldDate, 1, 0)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform