Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to determine the age of a person?
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00725626
Message ID:
00725840
Views:
14
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"
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform