You're right. I just tested 4 different versions of code I've found here from 1900 to today (including mine) all based on today's date and the below code seems to be the most reliable (and least verbose :o):
age= floor(INT((VAL(DTOS(DATE()))-VAL(DTOS(ldBirthday))))/10000)
>Tracy,
>
>Garrett's code is inaccurate with regard to leap birthday's, yours is probably accurate but quite verbose, when compared to Jim Booth's one liner. :)
>
>>Wow, I've been doing it different for years. Is there something wrong with the code below that I've been using?
>>
>>
>>*USAGE: REPLACE driver.age WITH GETAGE(driver.dob)
>>
>>*PROCEDURE getage
>>PARAMETERS m.birthday,m.comparedate
>>
>>PRIVATE m.yearsold
>>
>>* If only one parameter passed, use today's date as the date to
>>* compare to.
>>
>>IF PARAMETERS() = 1
>> m.comparedate = DATE()
>>ENDIF
>>
>>IF EMPTY(m.birthday)
>> RETURN 0
>>ENDIF
>>
>>* Verify compare DATE is a "DATE" type field. Convert if not.
>>
>>IF TYPE("m.comparedate") != "D"
>> m.comparedate = CTOD(m.comparedate)
>>ENDIF
>>
>>* Verify birthday DATE is a "DATE" type field. Convert it not.
>>
>>IF TYPE("m.birthday") != "D"
>> m.birthday = CTOD(m.birthday)
>>ENDIF
>>
>>* Find out how many years since birthday
>>
>>m.yearsold = YEAR(m.comparedate) - YEAR(m.birthday)
>>
>>* Find out if the "birtday" DATE has already passed by adding the
>>* current year to the end of the birthday.
>>
>>IF CTOD( ALLTRIM(STR(MONTH(m.birthday)))+'/'+ALLTRIM(STR(DAY(m.birthday)));
>> +'/'+ALLTRIM(STR(YEAR(m.comparedate))) ) > m.comparedate
>> m.yearsold = m.yearsold - 1
>>ENDIF
>>
>>RETURN m.yearsold
>>
>>
>>>>Given a birth day, say 11/02/56 or 11/02/1956, whats the best way to determine the current
>>>>age of this person?
>>>
>>>(DATE() - ldBirthday) / 365.24 should get you pretty close.
>>>
>>>Failing that, you could do a loop with GOMONTH(ldBirthday, 12*i) until you get a date greater than the current one.
.·*´¨)
.·`TCH
(..·*
010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"