Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to determine the age of a person?
Message
From
22/11/2002 11:57:23
 
 
To
22/11/2002 11:47:19
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00725626
Message ID:
00725844
Views:
13
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. :)

Oh, it's here if you didn't see it: Re: Reliably getting age from DOB and DATE() Thread #586710 Message #586842

>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
>
>
Steve Gibson
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform